Solving anti-vowel using pop


#1

I am using pop method to delete the element from the list. However , I am not able to remove the last element. Can any one explain why?


FAQ: Learn Python - Practice Makes Perfect - censor
#2

please include your code? So we can actually replicate the problem and come up with a solution

i generally advise against use del, remove and pop. Using this approach gives problems like you experience (not being able to remove last element from list), which should make your question if you shouldn’t have gone for a different approach in the first place


#3

Here we go.

def replace(text,word):

a = text.split()

for i in a:

if i == word:

a.remove(i)

print(a)

replace('he he he ',‘he’)


#4

You are creating a new string, removing from anything won’t bring you closer to that
Keep in mind that positions of elements in a list when you remove elements, how does that affect your loop?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.