Files
Mysteryhelfer/EinzelfunktionenExperimentierbereich/Anagramm/Anagramm-germandic.py

38 lines
1.1 KiB
Python

#!/usr/bin/python
# -*- coding: utf8 -*-
def buchstabenzaehl(buchstabe, anzahl):
if buchstabe in anzahl:
anzahl[buchstabe] = anzahl[buchstabe] + 1
else:
anzahl[buchstabe] = 1
def wortzaehl(wort):
anzahl = {}
for buchstabe in wort:
buchstabenzaehl(buchstabe.upper(), anzahl)
return anzahl
while 1:
print("Zum Beenden: kein Wort eingeben und Return drücken")
eingabe = input("Bitte Wort eingeben für welches Anagramme gesucht werden sollen: ")
eingabe = eingabe.rstrip()
if eingabe == "":
break
eingabezaehl = wortzaehl(eingabe)
wbfile = open("../../data/german.dic", "r") # german.dic von https://sourceforge.net/projects/germandict/
for line in wbfile:
line = line.strip(" \t\n\r")
if eingabe.upper() == line.upper():
continue
if len(eingabe) != len(line):
continue
if eingabezaehl == wortzaehl(line):
print(line)
wbfile.close()
print("---keine weiteren Anagramme gefunden---")
print()
print("Ich hoffe es hat geholfen! Bye,Bye!")