Kent Johnson wrote:
> It's handy to assign names to the individual elements of the list. A 
> variable named 'year' is a lot easier to understand than 'event[0]'. 
> This is easy to do with tuple unpacking:
> 
> In [6]: for event in events:
>     ...:     year, head, text = event
>     ...:     print 'In', year, head, text
>     ...:
>     ...:
> In 1863 headline1 event text1
> In 1992 headline2 event text2

The for loop and tuple unpacking can also be combined into the very elegant:

for year, head, text in events:
   print 'In', year, head, text

Kent


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to