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?

2
  • youvar.split(',') Commented May 27, 2018 at 19:03
  • add replace(' ', '') to remove whitespaces Commented May 27, 2018 at 19:07

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

That's exactly what I needed, thank you!
Great! Happy Coding.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.