I have one little problem with my python knowledge (novice ). The thing I'm trying to do is input list of strings to variable and then I'll need to do some for looping over the list and return few strings from list.
The problem is that I don't know how to input a list to variable.
Here's a code how I tried:
x=[]
x=(input('Please enter a list of strings: '))
...and then I entered ['car', 'house', 't-shirt', 'bicycle', 'images'] assuming that x will be a variable with list of strings but it's not.
Please help. Thx!
print repr(x)in order to see what's inxafter input. Oh, and you don't have to declare lists in python.x=[]will be overridden byinput('Please enter a list of strings: ')x = eval(x)but this is dangerous because malicious data can be entered. I'd propose you to make user input words through space or newline like thiscar house t-shirtand then just usex = x.split()after doing inputast.literal_eval()than to useeval()