On Thu, Jan 7, 2010 at 7:43 AM, Richard D. Moores <rdmoo...@gmail.com>wrote:
> On p. 162 of "Programming In Python", 2nd ed., by Summerfield, the > section entitled "for Loops" begins: > > ========================================= > for expression in iterable: > for_suite > else: > else_suite > > The expression is normally either a single variable or a sequence of > variables, usually in the form of a tuple. If a tuple or list is used > for the expression, each item is unpacked into the expression's items. > ====================================== > > I thought I was quite familiar with for loops, but I don't understand > how the expression can be a sequence of variables, nor what unpacking > into the expression's items means. Could someone explain this, > preferably with an example? > > Thanks, > > Dick Moores > > As an example, think of a list of tuples, similar to the following: tuplelist = [ (1, "a"), (2, "b"), (3, "c") ] To process them and handle each tuples elements individually, you can have the for statement: for (a, b) in tuplelist:
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor