'Find out different lengths with values in a two-dimensional list, depending on the number given as a parameter
Suppose I have a two-dimensional list mixed with True and False. I would like to create a function that gives me an additional parameter, which should be the number of elements to be output. The output should be like this:
For example, if I enter 3 as a number, the row and column in which 3 x True are located one after the other should be displayed.
So just the row and the first column
For example, in the list below:
3 x True in row: 1 and col: 3
lst = [[False, True, False, True, True, False],
[False, True, False, True, True, True],
[True, False, True, True, True]]
I've tried several options, but never found a solution. I have another small example here, but of course I get the wrong output:
def baz(count):
for row in range(len(lst)):
for col in range(len(lst[row])):
if lst[row][col] == lst[row][(col + count) % len(lst[row])] and lst[row][col] is True:
return (row, col)
print(baz(3))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
