John Bokma wrote:

And maybe you're right, the Python one could've been written:

if list is None:
   list = []

which looks, now, also more readable to me as well.

Though there's a slight difference[1], I'd usually use

  lst = lst or []

for your particular initialization use case.

-tkc

[1]
Difference being

  >>> lst = []
  >>> other = lst
  >>> if lst is None: # your code
  ...     lst = []
  ...
  >>> other.append(42)
  >>> lst, other
  ([42], [42])

  >>> lst = []
  >>> other = lst
  >>> lst = lst or [] # my proposal
  >>> other.append(42)
  >>> lst, other
  ([], [42])

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to