-
-
Save Jerry0420/0a721394780ec72df45bb627f98f57cd to your computer and use it in GitHub Desktop.
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 learning_path(first: str, second: str, third: str, fourth: str, target: str) -> str: | |
record: Dict[str, List[str]] = {} | |
for i in [first, second, third, fourth]: | |
rule = i.split(" ") | |
if len(rule) == 1: | |
record[rule[0]] = [] | |
else: | |
if rule[0] not in record: | |
record[rule[0]] = [] | |
rule[1:].sort() | |
record[rule[0]].extend(rule[1:]) | |
record[rule[0]].append(rule[0]) | |
result = record[target] | |
if len(result) <= 1: | |
return result | |
del record[target] | |
while True: | |
breakable = True | |
current_len = len(result) | |
for index in range(current_len): | |
temp = record.get(result[index], None) | |
if temp != None: | |
breakable = False | |
del record[result[index]] | |
if len(temp) >= 2: | |
temp.reverse() | |
del result[index] | |
for t in temp: | |
result.insert(0, t) | |
if breakable == True: | |
break | |
return " ".join(result) | |
result = learning_path( | |
"DataScience calculas stats", | |
"calculas counting", | |
"stats", | |
"counting", | |
"DataScience" | |
) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment