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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started