How to add values to an empty list of lists in Python

1 Answer

0 votes
lst = [[] for _ in range(5)]

lst[1].append(3)
lst[1].append(1)
lst[1].append(7)

lst[3].append(9)
lst[3].append(2)
lst[3].append(6)

print(lst)



'''
run:

[[], [3, 1, 7], [], [9, 2, 6], []]

'''

 



answered Mar 16, 2023 by avibootz
...