0

How can i convert an input into a list

20th Jun 2020, 11:39 AM
Krishna Agrawal
Krishna Agrawal - avatar
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.
20th Jun 2020, 11:51 AM
Lothar
Lothar - avatar
+ 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']
20th Jun 2020, 11:45 AM
Namit Jain
Namit Jain - avatar
+ 1
Python 3.7.7
20th Jun 2020, 11:45 AM
Krishna Agrawal
Krishna Agrawal - avatar