wrichik-basu

Untitled

Aug 20th, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. from typing import Dict, List, Set
  2. from copy import deepcopy
  3. from itertools import combinations
  4.  
  5.  
  6. def take_input() -> Dict[str, int]:
  7.  
  8.   names: List[str] = input().split(',')
  9.   birthdates: List[int] = [int(i) for i in input().split(',')]
  10.  
  11.   return dict(zip(names, birthdates))
  12.  
  13.  
  14. def reverse_dict(original: Dict[str, int]) -> Dict[int, Set[str]]:
  15.  
  16.   rev_dict: Dict[int, Set[str]] = {}
  17.  
  18.   for key, value in original.items():
  19.     rev_dict.setdefault(value, set()).add(key)
  20.  
  21.   return rev_dict
  22.  
  23.  
  24. def get_duplicates(rev_dict) -> List[Set[str]]:
  25.  
  26.   return [value for key, value in rev_dict.items() if len(value) > 1]
  27.  
  28.  
  29. def main() -> None:
  30.  
  31.   birth_dict = deepcopy(take_input())
  32.   rev_dict = deepcopy(reverse_dict(birth_dict))
  33.  
  34.   duplicates = deepcopy(get_duplicates(rev_dict))
  35.  
  36.   duplicates_sorted: str = ''
  37.  
  38.   for items in duplicates:
  39.    
  40.     items: List[str] = list(items)
  41.     items.sort()
  42.    
  43.     if len(items) > 2:
  44.      
  45.       for c in combinations(items, 2):
  46.        
  47.         c: List[str] = list(c)
  48.         c.sort()
  49.        
  50.         duplicates_sorted += ','.join(c) + '\n'
  51.    
  52.     else:
  53.       duplicates_sorted += ','.join(items) + '\n'
  54.  
  55.   print(duplicates_sorted, end='')
  56.  
  57.  
  58. if __name__ == '__main__':
  59.   main()
  60.  
Advertisement
Add Comment
Please, Sign In to add comment