Advertisement
AlexG2230954

Контрольная. Задание 4

May 28th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. from collections import Counter
  2.  
  3.  
  4. with open("input.txt", "r", encoding="utf-8") as file:
  5.     buys_count = Counter()
  6.     buys = [line.strip().split(",") for line in file.readlines()]
  7.  
  8.     for buy in buys:
  9.         buys_pairs = []
  10.         buy.sort()
  11.  
  12.         for i in range(len(buy)):
  13.             for j in range(i, len(buy)):
  14.                 if buy[i] != buy[j]:
  15.                     buys_pairs.append((buy[i], buy[j]))
  16.  
  17.         buys_count.update(buys_pairs)
  18.  
  19.     max_count = buys_count.most_common(1)[0][1]
  20.     max_buy = None
  21.  
  22.     for buy in buys_count.most_common():
  23.         if buy[1] == max_count:
  24.             if max_buy == None or buy[0] <= max_buy:
  25.                 max_buy = buy[0]
  26.  
  27.     print(",".join(max_buy))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement