Creating A Tuple From A List, Adding To Tuple As You Do

Terry Reedy tjreedy at udel.edu
Thu Jun 5 23:04:56 CEST 2008


"Karsten Heymann" <karsten.heymann at blue-cable.net> wrote in message 
news:87ej7casvr.fsf at ara.blue-cable.net...
| Hi Jeff,
|
| Jeff Nyman <jeffnyman at gmail.com> writes:
| > I did try this:
| >
| > for count in range(0, len(DC_List)):
| >     DC_List.insert(count, '')
|
| On additional note: You can be quite sure you'll never have to iterate
| over the length of a list (or tuple) in python. Just iterate over the
| list itself:
|
| for DC in DC_List:
|  # do something with DC.

Unless you want to modify the list in place.

for i in range(len(cities)):
    cities[i] = (cities[i], '')

#or perhaps better

for i,city in enumerate(cities):
    cities[i] = (city,'')

tjr






More information about the Python-list mailing list