How do I convert a space separated integer input into a list of integers?
Example input:
list1 = list(input("Enter the unfriendly numbers: "))
Example conversion:
['1', '2', '3', '4', '5'] to [1, 2, 3, 4, 5]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
map()is your friend, it applies the function given as first argument to all items in the list.since it maps every iterable, you can even do:
which (in python3.x) returns a map object, which can be converted to a list.
I assume you are on python3, since you used
input, notraw_input.