Ok so the working of this program is very simple, by using the input function called question I want to divide every character of what the user enters into an individual string that is then placed in a list, e.g. if the user enters: a,b,c i want the output to be stored in a list such as this list = ["a", ",", "b", ",", "c"]
then by using a for loop I want the index of every comma in the list to be found and thus removed, leaving only this as an output: list = ["a", "b", "c"]
. What am I doing wrong?
question =input(">")
def split(question):
return [char for char in question]
list = split(question)
print(list)
comma_index_ask = [i for i in range(len(list)) if list[i] == ","]
print(comma_index_ask)
for item in comma_index_ask:
list.pop(comma_index_ask[item])
print(list)
OUTPUT:
>a,b,c
['a', ',', 'b', ',', 'c']
Traceback (most recent call last):
File "C:main.py", line 14, in <module>
list.pop(comma_index_ask[item])
IndexError: list index out of range