map() return of flat tuple list
Mirco Wahab
wahab at chemie.uni-halle.de
Thu Jun 22 17:48:09 EDT 2006
Hi,
I have a 2D array,
maybe irregular, like
arr = [[2,2,2,2],
[2,2,2,2],
[2,2,2,2]]
if tried to pull an index list
(tuples or array elements) of
all positions - via the map funtion,
but failed.
I tried to get sth. like
[
[0,0],
[0,1],
[0,2],
...
]
for each element which really exists
in the 2D array above.
What I really got, was another in-
direction for each row of arr
[
[(0, 0), (0, 1), (0, 2), (0, 3)],
[(1, 0), (1, 1), (1, 2), (1, 3)],
...
]
How can I flatten the list in place by map(),
so that the outer map hull would collect
[i,j] flat?
This is what I tried:
id = map(lambda i: map(lambda j: (i,j), range(len(arr[i]))), range(len(arr)))
print id
I tried the map solution because I'd make a
shot at another posting (find min of 2D array),
what I intended to solve by decorate/undecorate
sort.
But I didn't manage to create the flat
coordinate list in one map(map)-stroke ;-)
Regards
Mirco
More information about the Python-list
mailing list