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

0 votes
asked Aug 6, 2016 by Hitesh Garg (799 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

+1 vote
answered Dec 7, 2016 by Rahul Singh (682 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 -

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

you can read complete about lists in this tutorial.