+ 2
I got a bug. Can anyone help me?
I was working with nested lists. I made these functions: def table(length, height): list = [] for i in range(height): list.append([]) for _ in range(length): list[i].append(0) return list def possible(length, height): table = table(length, height) list = [] for i in range(length): if table[0][i] == 0: list.append(i) return list This function should return a list of indexes, such that for every index in this list there should be a 0 in the first list of the table. But i get a bug: list index out of range Can anyone help me?
7 ответов
+ 5
Gašper Koželj There were a few things wrong with your original code which may not have been in the code you're working on.
I modified the original code to resolve the name collisions. However, there are other overall improvements I would have considered. But it's not fully clear what you're attempting to do.
https://code.sololearn.com/cxyrOybzzdIX/?ref=app
Since you seem to have it working in your version of the code, I'll leave it alone.
+ 1
What is length and height?
0
Length is 7, height is 6 in example, but this is a part of a bigger project with random possibilities.
0
The list returned by table is
[[0], [0],...,[0]]
0
Yeah i wrote the table wrong in the question. But it still doesnt work.
0
What output does it give you? (and what output are you expecting?)
0
I figured it out.
I did it like this:
row = table[0]
for i in range(length):
if row[i] ==0:
List.append(i)
return list