Palindromes
Next, you are committed to finding any peculiarity in the words included in the movie review dataset. A palindrome is a sequence of characters that can be read the same backward as forward, for example: Madam or No lemon, no melon. You realize that some funny movie names can have this characteristic. You want to make a list of all movie titles that are funny palindromes but you will start by analyzing one example.
In python, you can also specify steps by using a third index. If you don't specify the first or second index and the third one is negative, it will return the characters jumping and backward.
The text of a movie review for one example has already been saved in the variable movie. You can use print(movie) to view the variable in the IPython Shell.
Diese Übung ist Teil des Kurses
Regular Expressions in Python
Anleitung zur Übung
- Extract the substring from the 12th to the 30th character from the variable
moviewhich corresponds to the movie title. Store it in the variablemovie_title. - Get the palindrome by reversing the string contained in
movie_title. - Complete the code to print out the
movie_titleif it is a palindrome.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Get the word
movie_title = ____[____]
# Obtain the palindrome
palindrome = ____[____]
# Print the word if it's a palindrome
if movie_title == palindrome:
print(____)