I am doing a task for school in a beginner Python course that requires a function which removes all the words that are in capital letters using the string method isupper() and gives a new list as an output, which includes only the words that are not in all caps, for example:
List given:
my_list = ["ABC", "def", "UPPER", "ANOTHERUPPER", "lower", "another lower", "Capitalized"]
Expected output:
['def', 'lower', 'another lower', 'Capitalized']
This is what i currently have:
def no_shouting(my_list):
for word in my_list:
if word.isupper() == True:
my_list.remove(word)
return my_list
if __name__ == "__main__":
my_list = ["ABC", "def", "UPPER", "ANOTHERUPPER", "lower", "another lower", "Capitalized"]
pruned_list = no_shouting(my_list)
print(pruned_list)
Even though everything is seemingly fine to my rookie eyes, here is what my code gives as an output:
['def', 'ANOTHERUPPER', 'lower', 'another lower', 'Capitalized']
So for some reason, it does not remove the word "ANOTHERUPPER", but it removes every other uppercase word. How can I fix this?