python3 Example of entering the number of n in the same line and saving it in a list
- 2021-07-24 11:19:49
- OfStack
Recently, in the learning algorithm, it is often encountered that there are multiple data in one row, which are divided by spaces or ','. I didn't understand it at first, directly Baidu,
n = input()
n = int(n)
list1 = []
list1 = input().split()
list2 = []
i = 0
while i < n:
m = int(list1[i])
list2.append(m)
i += 1
print(list2)
But this is too much code. It also looks very wordy.
I have no intention of getting a new method under Experiment 1:
list1 = list(map(int,input().split()))
Not bad, everyone can try it!