On Sun, Feb 15, 2009 at 2:47 PM, Wayne Watson <sierra_mtnv...@sbcglobal.net> wrote: > I'm still looking for an explanation of "for (line_cnt, each_line) in > enumerate(input_file)". Why the tuple? Apparently, line_count gets a line > number, and each_line gets the string of text.
Do you know about sequence unpacking? In an assignment statement, when the right side is a sequence, the left side can be a list of variables of the same length as the sequence. Then each sequence element is assigned to one variable. For example, In [24]: item = (0, 'Spring') In [25]: i, season = item In [26]: i Out[26]: 0 In [28]: season Out[28]: 'Spring' This can be used in a for loop, too, if the items are sequences. That is what is commonly done with enumerate(). Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor