logo CodeStepByStep logo


Language/Type: Python lists traversals

Write a function named remove_palindromes that that removes all strings that are palindromes from a list of strings.

Your function accepts a list of strings as a parameter and modifies its contents, replacing every string in the list that is a palindrome with an empty string, "". For example, if a list named phrases stores the following element values:

a = ["Madam", "raceCAR", "", "hi", "A", "Abba", "banana", "dog God",
              "STOP otto POTS", "Madame", "Python", "LevEL", "staTS"]

Then the call of remove_palindromes(phrases) should change it to contain the following element values. Notice that the palindromes from the list such as "Madam" and "LevEL" have been replaced by "".

             ["", "", "", "hi", "", "banana", "", "", "Madame", "Python", "", ""]

Constraints: You are to modify the existing list in-place. Do not create any other data structures such as temporary lists. You may create as many strings as you like, and you may use as many simple variables as you like.

Note: You may want to go solve the string problem is_palindrome first and use it as part of your solution to this problem.

Type your Python solution code here:

This is a function exercise. Write a Python function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.