Sortierung der Dict nach count oder I(x_i)
This commit is contained in:
18
P1/main.py
18
P1/main.py
@@ -90,10 +90,24 @@ def calculate(elements, m, message):
|
||||
for x_i in elements:
|
||||
h += elements[x_i]["p(x_i)"] * elements[x_i]["I(x_i)"]
|
||||
|
||||
|
||||
sorted_by_element = sorted(elements)
|
||||
|
||||
sorted_by_count = dict(sorted(
|
||||
elements.items(),
|
||||
key = lambda item: item[1]["count"],
|
||||
reverse=True
|
||||
))
|
||||
|
||||
sorted_by_information = dict(sorted(
|
||||
elements.items(),
|
||||
key = lambda item: item[1]["I(x_i)"],
|
||||
reverse=True
|
||||
))
|
||||
# Ausgabe
|
||||
for x_i in elements:
|
||||
for x_i in sorted_by_information:
|
||||
print(f"{elements[x_i]["count"]:3.0f} | {elements[x_i]["I(x_i)"]:15.12f} | »{x_i}«")
|
||||
print("Entropie der Nachricht = " + h.__str__())
|
||||
print("Entropie der Nachricht = " + h.__str__() + "\n\n")
|
||||
|
||||
def main():
|
||||
Z_statistik()
|
||||
|
||||
Reference in New Issue
Block a user