I've got a problem where I need to add items to a list. It has to use stdin, and be in Θ(n). I only seem to be able to get it in Θ(n^2). This is my code:
for i in range(int(r1)): # size of list being made
for line in sys.stdin.readline().strip().split(" "):
a.append(line)
Input: Output: [1, 2, 3]
1
2
3
As far as I'm aware that's in Θ(n^2). I have tried doing this:
for i in range(int(r1)): # size of list being made
a.append(sys.stdin.readline().strip().split(" "))
Input: Output: [[1], [2], [3]]
1
2
3
Because the elements of the second attempt are in their own sub-lists then they don't work for the rest of my program. Any adivce?