Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def anagram(a, b):
- a, b = str(a), str(b)
- return sorted(a) == sorted(b)
- file, tempstr, record = [], "", []
- for a in open("words.txt"):
- for b in a:
- if b == ",":
- file.append(tempstr)
- tempstr = ""
- if b not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
- continue
- tempstr += b
- for c in file:
- anagrams = [c]
- for d in file:
- if c == d:
- continue
- if anagram(c, d):
- anagrams.append(d)
- if len(anagrams) == 1:
- del c
- continue
- if sorted(anagrams) not in record:
- record.append(sorted(anagrams))
- newrecord = []
- for e in record:
- if len(e[0]) == 5:
- newrecord.append(e)
- print(newrecord)
- lengthfive = []
- for x in range(10**10):
- if len(str(x**2)) < 5:
- continue
- if len(str(x**2)) > 5:
- break
- if len(set(str(x**2))) == len(str(x**2)):
- lengthfive.append(x**2)
- newerrecord = []
- for c in lengthfive:
- anagrams = [c]
- for d in lengthfive:
- if c == d:
- continue
- if anagram(c, d):
- anagrams.append(d)
- if len(anagrams) == 1:
- lengthfive.remove(c)
- continue
- if sorted(anagrams) not in newerrecord:
- newerrecord.append(sorted(anagrams))
- print(newerrecord)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement