Question: Python project. Code printing more than one line. I need it to only print one line each. The words parameter contains a list of two

Python project. Code printing more than one line. I need it to only print one line each.

The words parameter contains a list of two character

words (lower case, no duplicates). Using sets, find an O(n)

solution for displaying all symmetric pairs of words.

For example, if words was: [am, at, ma, if, fi], we would display:

am & ma

if & fi

The order of the display above does not matter. 'at' would not

be displayed because 'ta' is not in the list of words.

As a special case, if the letters are the same (example: 'aa') then

it would not match anything else (remember no the assumption above

that there were no duplicates) and therefore should not be displayed.

"""

def find_pairs(words):

word = []

for word in words:

reverse = ""

reverse = words[1] + word [0]

print(words, reverse)

find_pairs(["am","at","ma","if","fi"]) # ma & am, fi & if

print("=============")

find_pairs(["ab", "bc", "cd", "de", "ba"]) # ba & ab

print("=============")

find_pairs(["ab","ba","ac","ad","da","ca"]) # ba & ab, da & ad, ca & ac

print("=============")

find_pairs(["ab", "ac"]) # None

print("=============")

find_pairs(["ab", "aa", "ba"]) # ba & ab

print("=============")

find_pairs(["23","84","49","13","32","46","91","99","94","31","57","14"])

# 32 & 23, 94 & 49, 31 & 13

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!