I'm writting a program where the user has to input some random words like this:
Enter some words: apple, house, fire, guitar
and then I have to take this individual words (without the commas) and place them in a list. How do I take an input with several words and put them in a list?
You can try .split(',')
which returns list separated by ,
:
inp = input('Enter some words: ')
my_list = inp.split(',')
print(my_list)
Result:
Enter some words: apple, house, fire, guitar
['apple', ' house', ' fire', ' guitar']
Or, following would give same results too:
input_list = input('Enter some words: ').split(',')
print(input_list)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments