Thanks for all the good answers.

In fact the `Extended Iterable Unpacking' is exactly what I was looking for. 
Ok, my main aspect of writing

    head, *tail = seq

instead of

    head, tail = seq[0], seq[1:]

is the syntactic sugar. As mentioned in the PEP this may also be faster when 
iterables are involved.

Stefan

"Matimus" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
>> Is there a pattern matching construct in Python like (head : tail), 
>> meaning
>> 'head' matches the first element of a list and 'tail' matches the rest? I
>> could not find this in the Python documentation.
>
> Not really, but you could do something like this:
>
> [code]
> def foo(head, *tail):
>    #do stuff with head and tail
>
> foo(*seq)
> [/code]
>
> Also, Python 3.0 will have `Extended Iterable Unpacking'
> http://www.python.org/dev/peps/pep-3132/
>
> This isn't quite the same as Haskell's type matching, but would enable
> similar behavior in some cases.
>
> example:
> [code]
> head, *tail = seq
> [/code]
>
> Which would assign the first element of seq to head, and the remainder
> to tail.
>
> Matt
> 


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

Reply via email to