I am looking for a single line command in python to convert an integer input to list.
The following is the situation.
mylist=[]
mylist=list(input('Enter the numbers: '))
The above line works perfectly if i give more than one number as input. Eg 1,2,3 . But it gives Error when i give only a single digit entry. Eg: 1 . Saying it cannot convert an integer to list.
I don't want to run a loop asking user for each input. So i want a one line command which will work for one or more digits input given by user separated by commas.
Thanking you,
-indiajoe
解决方案
I think that the simplest thing that you can do is:
mylist = map(int, raw_input('Enter the numbers: ').split(','))
But it's nearly the same that using a list comprehension.