python list pattern matching?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri May 29 01:24:57 CEST 2009


Terry Reedy:
>  >>> a,b,*rest = list(range(10))
>  >>> a,b,rest
> (0, 1, [2, 3, 4, 5, 6, 7, 8, 9])
>  >>> a,*rest,b = 'abcdefgh'
>  >>> a,rest,b
> ('a', ['b', 'c', 'd', 'e', 'f', 'g'], 'h')

For the next few years I generally suggest to specify the Python
version too (if it's 2.x or 3.x).
This is Python 3.x.

Bye,
bearophile



More information about the Python-list mailing list