List. Help with list | SoloLearn: Learn to code for FREE!


List. Help with list

Hi! I've been programming for a month and I have a question. When I do this: nums = list([(input())]) print (nums) the output Is not a list of numbers, but a string. Something like "3,4,5,6" if the input was 3,4,5,6. Question: Can I make a list of numbers [3,4,5] with the help of "input"??? I know that you can do this : list [] and every time you enter the desired data, I need it with " input"

12/30/2018 10:19:59 AM

Sara H

4 Answers

New Answer


If i understand your question correctly then You can do this via using the split function split() method returns a list of strings after breaking the given string by the specified separator so it can be an way to get the desired output if you want to do something else then ping me. nums = input() numbers = list(map(int, nums.split())) print (numbers)


You can also do it this way: nums = [int(x) for x in input().split(',')] print(nums)


this is simple. x=input() #let x=1234 print(list(x)) #output=[1,2,3,4] If input in , Then try this. x=input() #let x=1,2,3,4 print(x.split(',')) output=[1,2,3,4] But remember in this list numbers is a string not an integer for that you can use int() function for it.


thank you very much