Advertisement
DeaD_EyE

koalitionen

Feb 23rd, 2025 (edited)
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import itertools
  2.  
  3.  
  4. def koalitionen(ergebnisse: dict, low_threshold: float, high_threshold: float):
  5.     for n in range(2, len(ergebnisse)):
  6.         for combo in itertools.combinations(ergebnisse.items(), r=n):
  7.             if low_threshold <= sum(e[1] for e in combo) <= high_threshold:
  8.                 total = f"{sum(e[1] for e in combo):.1f} %"
  9.                 koalition = " | ".join([e[0] for e in combo])
  10.                 print(total, koalition, sep=" | ")
  11.  
  12.  
  13. ergebnisse = {
  14.     "cdu": 28.5,
  15.     "afd": 20.6,
  16.     "spd": 16.4,
  17.     "grüne": 11.9,
  18.     "linke": 8.6,
  19.     # "bsw": 4.9,
  20.     # "fdp": 4.5,
  21.     # "sonstige": 4.6,
  22. }
  23.  
  24. koalitionen(
  25.     ergebnisse,
  26.     50.0,
  27.     60,
  28. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement