How to get a 'list' as in input from user in python?

0 votes
63 views
asked Aug 6, 2016 by Hitesh Garg (135 points)  

I am using raw_input("Enter all names - ") to take the input of user names but it is always read as a string. I want to read it as a list, how should I do that and what is the most optimized way to do this?

1 Answer

0 votes
answered Dec 8, 2016 by Rahul Singh (163 points)  

To read it as a list you need to have a separator in the input which will be used to define the different list items.
Lets say these values are space separated then to take input in python 3 -

s=input()
a=list(s.split(" "))  # " " is the words separator
print(a)

you can read complete about lists in this tutorial.

...