by aston · 15y ago · 0 comments
stuff = stuff or []
because if you pass an empty list, you'll get a new one rather than mutating the one you passed. stuff = stuff if stuff is not None else []
is wordy, but at least it's correct. if stuff is None:
stuff = []If I were being cavalier and had an extra wish to burn, I'd request
x else y
to mean x unless x is None.Dammit, people - in Python, "That's clever" is an insult. Learn the philosophy of a language and you'll be much happier using it.
stuff = stuff is not None and stuff or []
That said, the `if stuff is not None:` is the most Pythonic way of doing it.