blob: ca1d4678bbacb2e52a89534c32a4f9cc6cfe5328 (
plain)
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
|
fn = "/usr/share/dict/words"
ourlist = [] # words file but the words letters are rearranged
with open(fn,"r") as file:
lines = file.readlines()
file.close()
for i in range(len(lines)):
lines[i] = lines[i].lower().rstrip("\n")
for line in lines:
ourlist.append(''.join(sorted(line))) # letters in alphabetical order
thelist = sorted(ourlist)
maxlen = 0
maxword = ""
flag = 0
cnt = 0
for i in range(len(thelist) - 1):
if len(thelist[i]) < 4:
continue
if flag == 1:
if thelist[i+1] != thelist[i]:
flag = 0
cnt += 1
if maxlen < cnt:
maxlen = cnt
maxword = thelist[i]
cnt = 0
else:
cnt += 1
if thelist[i+1] == thelist[i]:
if flag == 0:
flag = 1
cnt = 1
print(maxword, maxlen)
|