map() return of flat tuple list

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Jun 22 18:57:57 EDT 2006


Maybe you want something like this (but this doesn't use map):

def indexes(m):
    return [(r,c) for r, row in enumerate(m) for c in xrange(len(row))]

m1 = [[2,2,5],
      [2,2],
      [2,2,2,2]]

m2 = [[],
      [2],
      [1,2,3,4]]

print indexes(m1)
print indexes(m2)

Output:
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (2, 0), (2, 1), (2, 2), (2,
3)]
[(1, 0), (2, 0), (2, 1), (2, 2), (2, 3)]

Bye,
bearophile




More information about the Python-list mailing list