Python inline if statement

This

twins[value] = twins[value] + [box] if value in twins else [box]

is functionally equivalent to this:

if value in twins:
    tmp = twins[value] + [box]
else:
    tmp = [box]
twins[value] = tmp

Leave a Comment