Untitled

mail@pastecode.io avatar
unknown
python
a month ago
907 B
2
Indexable
Never
# Write a function findWord that takes a list of letter combinaisons in input, and returns the
# word issued from the combinaisons. There is always a unique solution.

# assert findWord(["P>E", "E>R", "R>U"]) == "PERU"
# assert findWord(["I>N", "A>I", "P>A", "S>P"]) == "SPAIN"
# assert findWord(["U>N", "G>A", "R>Y", "H>U", "N>G", "A>R"]) == "HUNGARY"
# assert findWord(["I>F", "W>I", "S>W", "F>T"]) == "SWIFT"
# assert findWord(["R>T", "A>L", "P>O", "O>R", "G>A", "T>U", "U>G"]) == "PORTUGAL"
# assert findWord(["W>I", "R>L", "T>Z", "Z>E", "S>W", "E>R", "L>A", "A>N", "N>D", "I>T"]) == "SWITZERLAND"


import random
import math

t = ["P>E", "E>R", "R>U"]

z = []
w = {}
text = ""
for item in t:
    sp = item.split(">")
    w.update({sp[0]: sp[1]})
    print(sp[0])
    print(sp[1])
    print(w)
    if sp[0] == w[sp[1]]:
        text += sp[0]
    z.extend(sp)
print(text)
print("len: ",len(list(set(z))))
Leave a Comment