-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogrammingchallenge1-try2.py
41 lines (33 loc) · 1.04 KB
/
programmingchallenge1-try2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# This is my second try for the programming challenge 1 (Unscramble the words)
import os
wordobj = open("wordlist.txt", "r+")
wordlist = wordobj.read()
scrambledwords = []
for i in range(10):
inp = str(input("enter the given words: "))
scrambledwords.append(inp)
for item in scrambledwords:
print("\n"+item)
list = wordlist.split('\n')
sortedscram = []
sortedlist = []
for scram in scrambledwords:
scramb = ''.join(sorted(scram))
sortedscram.append(scramb)
for scram in list:
scramb = ''.join(sorted(scram))
sortedlist.append(scramb)
dictos = {}
for i in range(0, 1276):
dictos[list[i]] = sortedlist[i]
print()
listofsoles = []
for ss in sortedscram:
for sc in sortedlist:
if sc == ss:
for scrambled, unscrambled in dictos.items():
if ss == unscrambled:
print(scrambled + " is the solution to %s"%(ss))
listofsoles.append(scrambled)
for i in listofsoles:
print(i+",",sep=' ', end='', flush=True)