Answer the question
In order to leave comments, you need to log in
Why is it not working correctly?
a='a abc ccc cvv v'
b=a.split()
c=[]
for i in b:
if len(i)>=3 and len(i)<=5:
c.append(i)
b.remove(i)
Answer the question
In order to leave comments, you need to log in
If you need to "find and delete" at the same time, then you CAN do this only from the end of the list
a='a abc ccc cvv v'
b=a.split()
c=[]
for i in b[::-1]:
if len(i)>=3 and len(i)<=5:
c.append(i)
b.remove(i)
print ( c)
print (b)
['cvv', 'ccc', 'abc']
['a', 'v']
c.reverse()
print ( c)
['cvv', 'ccc', 'abc']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question