Universally unpacking tuples

Roberto Lupi Roberto at lupi.an.it
Mon Sep 23 02:42:35 EDT 2002


In article <158d3913.0209222233.123a9675 at posting.google.com>, 
peter.bittner at gmx.net says...
> The root of the problem is that I am forced to move from a
> list-solution (iterating over the elements of a list) to a
> tuple-solution (iterating over the elements of a tuple). So, what I am
> trying to do with the above code is nothing more than migrating the
> following list-oriented code to a tuple-thing:
> 
> mylist = ['abc', '123', 'qwert', ...]
> for i in range(len(mylist)):
>   elem = mylist[i]
>   print elem
> 
> 
> Does anyone know a simple solution to this problem?

mylist = ('abc', '123', 'qwert', ...)
for i in range(len(mylist)):
  elem = mylist[i]
  print elem

Or better:

for x in mylist:
  print x

-- 
Roberto Lupi



More information about the Python-list mailing list