+ 2
Can I create 2d or 3d matrices just by declaring it's elements one by 1 in loop like a[i][j] by looping I and j? (In python)
2 Respostas
+ 1
I think so. What’s the context?
In Python I think when you create a list, it starts as an empty list. So you would be appending, not assigning, in the loop:
a = []
i = 0
while i < 10:
a.append([])
j = 0
while j < 5:
a[i].append(input())
j += 1
i += 1
+ 7
I would recommend nested loops. First for first dimension, second - for second and so on.