I tried to use
raw_input() to get a list of numbers, however with the code
numbers = raw_input() print len(numbers)
[1,2,3] gives a result of
7, so I guess it interprets the input as if it were a string. Is there any direct way to make a list out of it? Maybe I could use
re.findall to extract the integers, but if possible, I would prefer to use a more Pythonic solution.
In Python 3.x, use this.
a = [int(x) for x in input().split()]
>>> a = [int(x) for x in input().split()] 3 4 5 >>> a [3, 4, 5] >>>
It is much easier to parse a list of numbers separated by spaces rather than trying to parse Python syntax:
s = input() numbers = list(map(int, s.split()))
s = raw_input() numbers = map(int, s.split())