+ 1
What wrong with this? Why the output not is ["p","y","t","h","o","n"]
stg=list(" py th on ") for c in stg: if c is " ": stg.remove(" ") print(stg)
8 Respuestas
+ 6
You're changing the list while you're iterating over it. That's generally not a good idea. You can use a print statement in the for loop to see how the list changes dynamically
+ 5
Gordon My answers are still several pages long if you display them on a very small screen 😏
+ 4
Anna, you changed🤭. You used to give very detailed explanation in each step. Page length answers.
+ 4
you could also use:
stg=list(" py th on ")
print(list(filter(lambda x: x != ' ', stg)))
+ 3
stg = [c for c in stg if c != ' ']
or:
stg=list(" py th on ")
while ' ' in stg:
stg.remove(" ")
+ 1
Thanks for the answers!😁
+ 1
I've solved my problem. Thanks again!
https://code.sololearn.com/cyQMHg2nl5Ou/?ref=app