[BangPypers] Iterating list of tuples

Anand Chitipothu anandology at gmail.com
Mon Jul 4 09:38:10 CEST 2011

>        for i in data[0]: # Iterate over elements of the tuple
>             if i > 5:
>                print "greater"
>             else:
>                print "lesser"
> `value` in your code does not mean the index, it's the actual element
> itself.

It is unsaid rule that variables i, j and k are used for loop indexes.
It is confusing if you use them for other values, esp. in loops.

This reads better:

for x in data[0]:
    if x > 5:
        print "greater"
        print "lesser"


More information about the BangPypers mailing list