Re: Haskell like (c:cs) syntax

2007-08-29 Thread Carl Banks
On Tue, 28 Aug 2007 17:30:47 -0500, Erik Jones wrote: > On Aug 28, 2007, at 5:12 PM, Chris Mellon wrote: >> When working with lists, Python has a slice syntax (which is rather >> more powerful than Haskells limited head->tail linked list syntax) that >> you can use to chop a sequence up into variou

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Erik Max Francis
Marco Mariani wrote: > Ricardo Aráoz ha scritto: > >> L = ['one', 'two', 'three', 'four', 'five'] >> >> print L[0]# This would be 'head' >> print L[1:] # This would be 'tail' >> >> Caution : L[0] and L[1:] are COPIES of the head and tail of the list. > > This might surprise people who see L

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Stefan Niemann
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

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Steve Holden
Istvan Albert wrote: > On Aug 29, 8:12 am, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Caution : L[0] and L[1:] are COPIES of the head and tail of the list. > >> Sorry, should have written RETURN copies instead of ARE copies. > > L[0] does not return a copy, it does what is says, returns the

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Istvan Albert
On Aug 29, 8:12 am, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > >> Caution : L[0] and L[1:] are COPIES of the head and tail of the list. > Sorry, should have written RETURN copies instead of ARE copies. L[0] does not return a copy, it does what is says, returns the object stored at index 0. i.

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Ricardo Aráoz
Marco Mariani wrote: > Ricardo Aráoz ha scritto: > >> L = ['one', 'two', 'three', 'four', 'five'] >> >> print L[0]# This would be 'head' >> print L[1:] # This would be 'tail' >> >> Caution : L[0] and L[1:] are COPIES of the head and tail of the list. > > This might surprise people who see L

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Nick Craig-Wood
Erik Jones <[EMAIL PROTECTED]> wrote: > front, last = l[:len(l) - 1], l[len(l) - 1] Normally written as front, last = l[:-1], l[-1] -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Marco Mariani
Ricardo Aráoz ha scritto: > L = ['one', 'two', 'three', 'four', 'five'] > > print L[0]# This would be 'head' > print L[1:] # This would be 'tail' > > Caution : L[0] and L[1:] are COPIES of the head and tail of the list. This might surprise people who see L[1:] = [], since changing a copy

Re: Haskell like (c:cs) syntax

2007-08-28 Thread Matimus
> 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

Re: Haskell like (c:cs) syntax

2007-08-28 Thread Erik Jones
On Aug 28, 2007, at 5:12 PM, Chris Mellon wrote: > On 8/28/07, Stefan Niemann <[EMAIL PROTECTED]> wrote: >> Hi, >> >> sorry that I'm relatively new to Python. But the syntax and >> semantics of >> Python already fascinate me, because I'm familiar with functional >> languages >> like Haskell.

Re: Haskell like (c:cs) syntax

2007-08-28 Thread Paul Rubin
"Stefan Niemann" <[EMAIL PROTECTED]> writes: > 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. Python's lists are actually linear arrays. Yo

Re: Haskell like (c:cs) syntax

2007-08-28 Thread Ricardo Aráoz
Stefan Niemann wrote: > Hi, > > sorry that I'm relatively new to Python. But the syntax and semantics of > Python already fascinate me, because I'm familiar with functional languages > like Haskell. > > Is there a pattern matching construct in Python like (head : tail), meaning > 'head' matche

Re: Haskell like (c:cs) syntax

2007-08-28 Thread Chris Mellon
On 8/28/07, Stefan Niemann <[EMAIL PROTECTED]> wrote: > Hi, > > sorry that I'm relatively new to Python. But the syntax and semantics of > Python already fascinate me, because I'm familiar with functional languages > like Haskell. > > Is there a pattern matching construct in Python like (head : tai

Haskell like (c:cs) syntax

2007-08-28 Thread Stefan Niemann
Hi, sorry that I'm relatively new to Python. But the syntax and semantics of Python already fascinate me, because I'm familiar with functional languages like Haskell. Is there a pattern matching construct in Python like (head : tail), meaning 'head' matches the first element of a list and 'tai