python - Find which row/sublist a value is in -
i'm trying find out row value in , not having much luck. have found lots of examples of working columns , rows on stackoverflow haven't been able find this, because it's easy , don't it. 1 help me.
for example, have list of integers starting 0 99, in 10 rows , 10 columns. row value 17 reside in, assuming don't know pattern of values in lists?
the list
[[0,1,2,3,4,5,6,7,8,9], [10,11,12,13,14,15,16,17,18,19], ...]
for reply i'm assuming want find sublists value in within list of lists values in inner lists don't follow specific pattern create computation of sublist value in trivial.
suppose have list lst
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [7, 12, 13]] where each sublist "row". if want know in sublists/rows value in (let's take find == 7 demo), can do:
>>> find = 7 >>> [x[0] x in enumerate(lst) if find in x[1]] [2, 4] find in row/sublist 2 , 4, counting zero.
if want know rows and columns, can issue:
>>> [(x[0],y[0]) x in enumerate(lst) y in enumerate(x[1]) if y[1] == find] [(2, 1), (4, 0)] find in row 2, column 1 , in row 4, column 0.
python
No comments:
Post a Comment