Collections.deque()

  • + 12 comments

    It is equivalent to:

    if len(inp) > 1:
        getattr(d, inp[0])(inp[1])
    else:
        getattr(d, inp[0])
    

    In order to get it all on one line, you have to use a x if y else z form statement, so you want to say getattr(d, inp[0])(inp[1] if len(inp) > 1 else something) because you have to put an else something at the end of the statement, and it has to be an expression, so the easiest way to get nothing is to use the star operator on an empty list, because the star operator takes the contents of a list out of their list, so we have inp[1] if len(inp) > 1 else *[] but that is invalid syntax, because the asterisk has to go at the beginning of the x if y else z, so we have to put inp[1] in a list too, leaving getattr(d, inp[0])(*[inp[1] if len(inp) > 1 else *[])

    Let me know if you need more clarification.