1

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?

Sara
  • 103
  • 1
  • 7

1 Answers1

0

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)
niraj
  • 17,498
  • 4
  • 33
  • 48