I'm wondering how to take user input and make a list of every character in it.
magicInput = input('Type here: ')
And say you entered "python rocks" I want a to make it a list something like this
magicList = [p,y,t,h,o,n, ,r,o,c,k,s]
But if I do this:
magicInput = input('Type here: ')
magicList = [magicInput]
The magicList is just
['python rocks']
Use the built-in list()
function:
magicInput = input('Type here: ')
magicList = list(magicInput)
print(magicList)
Output
['p', 'y', 't', 'h', 'o', 'n', ' ', 'r', 'o', 'c', 'k', 's']
It may not be necessary to do any conversion, because the string supports many list operations. For instance:
print(magicInput[1])
print(magicInput[2:4])
Output:
y
th
Another simple way would be to traverse the input and construct a list taking each letter
magicInput = input('Type here: ')
list_magicInput = []
for letter in magicInput:
list_magicInput.append(letter)
or you can simply do
x=list(input('Thats the input: ')
and it converts the thing you typed it as a list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With