Re: Walking lists

2010-02-25 Thread Mensanator
On Feb 25, 7:02 am, Tim Chase wrote: > Python 3 introduced a variable tuple assignment which I > suspect[*] would work in this context: > >    for first, *rest in L: # note the asterisk >      print first >      for x in rest: >        do_stuff(x) > > [*] not having py3 on this machine, I can't re

Re: Walking lists

2010-02-25 Thread Jean-Michel Pichavant
lallous wrote: Thank you all for the replies. The solution using Python 3's syntax look very intuitive. Thanks Tim, Arnaud for the idea (I am using 2.x) -- Elias On Feb 25, 1:28 pm, lallous wrote: Hello I am still learning Python, and have a question, perhaps I can shorten the code: L =

Re: Walking lists

2010-02-25 Thread lallous
Thank you all for the replies. The solution using Python 3's syntax look very intuitive. Thanks Tim, Arnaud for the idea (I am using 2.x) -- Elias On Feb 25, 1:28 pm, lallous wrote: > Hello > > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( >   (1,

Re: Walking lists

2010-02-25 Thread Arnaud Delobelle
lallous wrote: > Hello > > > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > for x in L: > print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_res

Re: Walking lists

2010-02-25 Thread Tim Chase
lallous wrote: L = ( (1, 2, 3), (4,), (5,), (6, 7) ) What I want, is to write the for loop, something like this: for (first_element, the_rest) in L: print first_element for x in the_rest: # now access the rest of the elements Python 3 introduced a variable tuple assignment whi

Re: Walking lists

2010-02-25 Thread Peter Otten
lallous wrote: > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > for x in L: > print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L:

Walking lists

2010-02-25 Thread lallous
Hello I am still learning Python, and have a question, perhaps I can shorten the code: L = ( (1, 2, 3), (4,), (5,), (6, 7) ) for x in L: print x What I want, is to write the for loop, something like this: for (first_element, the_rest) in L: print first_element for x in the_res