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
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
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
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
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.
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
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
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
> 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
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.
"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
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
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
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
14 matches
Mail list logo