How to append multiple strings from a single input into a list in Python

Sara

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?

student

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to append a multiple dictionaries to a list from a loop, python?

How to take either multiple or single input on one line from Python

How to append to a list from multiple list in r?

how to append multiple users input to a dictionary in python?

How to strip multiple unwanted characters from a list of strings in python?

How to append strings from a loop to a single output line?

BeautifulSoup Python3 append multiple links output to single list

How to append to a List of strings with values from another List?

How to append multiple values to a list in Python

Append strings to list from string

How to append multiple strings in Groovy?

How to append strings to a list in a dictionary

How to remove multiple strings from a list by letter?

How to create multiple dictionaries from a list of strings?

How to append list of numerous types to single string (python)

How to remove numbers from strings in a list using one single for loop in python3?

how to convert multiple strings into list using python

How to store multiple strings in list in Python?

How can I append list items from input with effects

How to append each item from a list to a list in a list in Python?

Is it possible to remove all single quotes from a list of strings in python?

how to append list with user input

How can I remove two or more objects of a list from a single input in Python?

How to create multiple links from a single array of strings Rails - Ruby

Check if input is a list/tuple of strings or a single string

how to open multiple file from single file which is having list of files in python and how to do processing on them?

How to cast the output of a for loop into a single list of strings in Python?

Extracting information from input list of strings by using regular expression in Python

Multiple scanf from a single input