I am using list comphrensions for this:
x = [i for i in int(raw_input("Enter Input:")).split(",")]
Enter Input : 1 2 3 4 5
But it throws the error:
Traceback (most recent call last):
File "python", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1 2 3 4 5'
Can someone please sort it out.
zhm
3,6814 gold badges39 silver badges57 bronze badges
1 Answer 1
x = [int(i) for i in raw_input("Enter Input:").split(" ")]
answered Mar 31, 2017 at 3:26
repzero
8,4203 gold badges21 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
',', just split with a space.....split(). Moreover split will give you an array of values. You will have to iterate over each element and type cast toint.