Re: elegant python style for loops

2007-05-10 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > To step through a list, the python style is avoid an explicit index. > But what if the same hidden index is to be used for more than one list > > for example:- > for key,value in listKeys,listValues : > newdict[key]=value newdict = dict(zip(listKeys, listValues

Re: elegant python style for loops

2007-05-10 Thread Ant
On May 10, 6:51 am, [EMAIL PROTECTED] wrote: ... > into a list of tuples to allow moving through multiple lists, or is > the for i in range(len(listkeys)): the only solution? > > Any suggestions? For the specific case of indexing lists, the following is cleaner than the 'for i in range...' solutio

Re: elegant python style for loops

2007-05-10 Thread ian . team . python
On May 10, 6:00 pm, [EMAIL PROTECTED] wrote: > thank you everybodyvery well answered.just one question > remains > where do i find documentation on zip ...i was looking for a function > like this, but could not even find a relevant list of functions!! ooops...even that was answered. ag

Re: elegant python style for loops

2007-05-10 Thread ian . team . python
thank you everybodyvery well answered.just one question remains where do i find documentation on zip ...i was looking for a function like this, but could not even find a relevant list of functions!! -- http://mail.python.org/mailman/listinfo/python-list

Re: elegant python style for loops

2007-05-09 Thread Asun Friere
On May 10, 4:20 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > for a, b in zip(lista, listb): > ... You don't even need the for loop nowadays. Just pass the zipped list to a dictionary constructor thusly: newdict = dict(zip(listKeys,listValues)) Asun -- http://mail.python.org/mailman

Re: elegant python style for loops

2007-05-09 Thread Peter Otten
[EMAIL PROTECTED] wrote: > To step through a list, the python style is avoid an explicit index. > But what if the same hidden index is to be used for more than one list > > for example:- > for key,value in listKeys,listValues : > newdict[key]=value > > won't work as it is a tuple of lists,

Re: elegant python style for loops

2007-05-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > To step through a list, the python style is avoid an explicit index. > But what if the same hidden index is to be used for more than one list > > for example:- > for key,value in listKeys,listValues : > newdict[key]=value > > won't work as it is a tuple of lists

Re: elegant python style for loops

2007-05-09 Thread Gary Herron
[EMAIL PROTECTED] wrote: > To step through a list, the python style is avoid an explicit index. > But what if the same hidden index is to be used for more than one list > > for example:- > for key,value in listKeys,listValues : > newdict[key]=value > > won't work as it is a tuple of lists, as