I started a project where I turn a string into a list, and in the list I turn each index into another list. However, I ran into a problem. My code is below:
# Define the string
string = "Hello there!"
# Print string (Hello there!)
print(string)
# Define string_list and assign it to the list version of a string
string_list = list(string)
# Print string_list
print(string_list)
''' # ['H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e', '!'] '''
for i in string_list:
i = list(i)
print(string_list)
''' ['H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e', '!'] '''
When I try to turn each index of the string_list
into another list, it doesn't work. What I want is for the output of the final print of string_list
to look like this:
[['H'], ['e'], ['l'], ['l'], ['o'], [' '], ['t'], ['h'], ['e'], ['r'], ['e'], ['!']]
Is there a way I can do this similar to my original method? Also, why does my original method not do what I want it to do? Thank you in advance.