how to separate a list into two lists?
steve+comp.lang.python at pearwood.info
Sun Aug 7 02:13:02 CEST 2011
> I'll have to check up on the *L - is that a reference?
No, as Chris already answered, unary * is used for packing and unpacking
positional arguments to functions; unary ** is similarly used for
collecting keyword arguments.
> I know in Perl, you can assign the lhs to a list,
> below works because there are exactly 2 items on the rhs.
> Does Python have a catchall, or an ignore the rest?
Yes. In Python 3, you can do this:
>>> a, b, *t, c = (1, 2, 3, 4, 5, 6, 7, 8, 9)
[3, 4, 5, 6, 7, 8]
(but not in Python 2)
More information about the Python-list