- 1
How to take n space separated Integer in a list in python?
If n=3 then input 3 Integer value separated by space
3 Antworten
+ 8
lst = [int(i) for i in input().split()][:n]
- 1
Yeah its working.. Thanks.
- 2
Easy solution is just to use the string method split.
input: 5 8 0 sgshsu 123
input.split(" ") == ["5", "8", "0", "sgshsu", "123"]
#Then they are easy to convert to numeric datatypes, but invalid inputs might raise errors.