Created
March 20, 2023 16:13
-
-
Save darighost/e7b965f58022cfd692dad76d8085f927 to your computer and use it in GitHub Desktop.
Helping my daughter with a codewars problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reversed_pairs(wordlist): | |
if len(wordlist) == 0: | |
return [] | |
word = wordlist[0] | |
other_words = wordlist[1:] | |
pair = [] | |
for w in other_words: | |
if word[::-1] == w: | |
pair = [[word, w]] | |
break | |
return pair + reversed_pairs(other_words) | |
print(reversed_pairs(['hi', 'hello', 'ih', 'the', 'olleh'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment