36.7k views
0 votes
Two words are a ""reverse pair"" if each is the reverse of the other. Write a program that finds all the reverse pairs in the word list.

User Dagob
by
5.4k points

1 Answer

2 votes

Answer:

The code written in python is attached.

Step-by-step explanation:

  1. I defined a function called find_reverse_pairs
  2. The function accepts word_list as an input
  3. I import the library itertools to put all possible pairs in the word_list to a list called pairs. I also created an empty list reverse_pairs to collect the desired pairs.
  4. For all the pairs in the pairs list, if their length is equal and they are reverse of each other, I append the pair to the reverse_pairs list
Two words are a ""reverse pair"" if each is the reverse of the-example-1