Tuple question

Dan Christensen jdc at uwo.ca
Fri Sep 3 05:27:05 CEST 2004

Jason Lai <jmlai at uci.edu> writes:

> Dan Christensen wrote:
>>     for row in rows:
>>         try:
>>             points += 3-row.index(X)
>>         except:
>>             pass
>> I realize that there are different ways to code it, but most
>> are simply reimplementations of the proposed index function.
>> Dan
> for index, row in enumerate(rows):
>     points += 3 - index

[I changed "i" to "index" in the last line.]

That doesn't do the same thing, but that's because my description
wasn't clear.  rows is a list of tuples, with each tuple being one
person's three votes.  E.g.

rows = [('J2', 'C64', 'X11'), ('U2', 'J2', 'P3000')]

So if X == 'J2', the code should calculate 3+2=5 points.


More information about the Python-list mailing list