-1

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.

6
  • 1
    Don't split with ',' , 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 to int. Commented Mar 31, 2017 at 3:22
  • I have just tried that, still not working Commented Mar 31, 2017 at 3:24
  • can u please upload the code Commented Mar 31, 2017 at 3:24
  • [int(i) for i in input().split()] this will by default split by space Commented Mar 31, 2017 at 3:25
  • 1
    thnx @Rednivrug Commented Mar 31, 2017 at 3:27

1 Answer 1

1
x = [int(i) for i in raw_input("Enter Input:").split(" ")]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.