Skip to content

Instantly share code, notes, and snippets.

@darighost
Created March 20, 2023 16:13
Show Gist options
  • Save darighost/e7b965f58022cfd692dad76d8085f927 to your computer and use it in GitHub Desktop.
Save darighost/e7b965f58022cfd692dad76d8085f927 to your computer and use it in GitHub Desktop.
Helping my daughter with a codewars problem
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