I tried to use raw_input()
to get a list of numbers, however with the code
numbers = raw_input()
print len(numbers)
the input [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.
It is much easier to parse a list of numbers separated by spaces rather than trying to parse Python syntax:
Python 3:
Python 2:
Answer is trivial. try this.
x=input()
Suppose that
[1,3,5,'aA','8as']
are given as the inputsprint len(x)
this gives an answer of 5
print x[3]
this gives
'aA'
In Python 3.x, use this.
Example