0
How can i convert an input into a list
4 Respuestas
+ 6
A simple way is to split input by word boundary like this:
inp = input('enter some words: ').split() # inp gets a list
If you want to get each character separated in a list, do it like:
inp = list(input('enter a word: ')) # inp gets also a list
In general, there are some more possible ways to get input to a list. if you already have an input as string, you can also use list() or split() like mentioned above.
+ 2
If the input is "abc abc abc":
You can use two ways:
1.
x = list(input())
print(x)
Output: ['a', 'b', 'c',' ', 'a', 'b', 'c', ' ', 'a', 'b', 'c']
2.
x = input()
x = x.split(" ")
print(x)
Output: ['abc', 'abc', 'abc']
+ 1
Python 3.7.7