Lists into lists

Neil Schemenauer nas at python.ca
Mon Aug 20 16:27:13 EDT 2001


Mark Day wrote:
> As another poster mentioned, you could use list(y) instead of y[:].
> 
> Can anyone offer guidance about which one to choose?  Are there subtle
> differences in behavior?  Is one better than the other when y is a
> user-defined class (such as a UserList derivative) vs. a built-in type?

list(y) returns an object of type "list".  y[:] returns a copy of the
sequence, maintaing the type.  Use list() if you want to be sure you get
a list otherwise use the slice notation.  If you don't like the slice
notation use copy.copy().

  Neil




More information about the Python-list mailing list