George_Zagorsky_1

Untitled

Apr 29th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. '''
  2. Дан список чисел, нужно вывести элемент у которого нет дупбиката
  3.  
  4. 1) Решение через count
  5. 2) Решение через словарь
  6. 3) Решение через доп список
  7.  
  8. '''
  9.  
  10.  
  11. def count_posibility(arr):
  12.     for el in arr:
  13.  
  14.         if arr.count(el) == 1:
  15.             return el
  16.  
  17.     return None
  18.  
  19.  
  20. def dictionary_posibility(arr):
  21.     dictionary = {}
  22.  
  23.     for element in arr:
  24.  
  25.         if element not in dictionary.keys():
  26.             dictionary[element] = 0
  27.         else:
  28.             dictionary[element] += 1
  29.  
  30.     for element in dictionary.values():
  31.  
  32.         if element == 0:
  33.             return element
  34.  
  35.     return None
  36.  
  37.  
  38. def tuple_posibility(arr: list):
  39.     stack = []
  40.     arr.sort()
  41.     for element in arr:
  42.  
  43.         if element not in stack:
  44.  
  45.             stack += [element]
  46.  
  47.         elif (element not in stack) and (type(tuple) in stack):
  48.  
  49.             for el in stack:
  50.  
  51.                 if type(el) == list:
  52.  
  53.                     if el[0] == element:
  54.  
  55.                         index = stack.index(el)
  56.                         i = 0
  57.                         while i < len(stack):
  58.  
  59.                             if i == index:
  60.                                 stack.pop(index)
  61.                                 break
  62.  
  63.                             i += 1
  64.         else:
  65.  
  66.             result = stack.pop()
  67.             print(type(tuple[element]))
  68.             stack.append([element])
  69.  
  70.     x_stack = []
  71.  
  72.     for element in stack:
  73.  
  74.         if type(element) == list:
  75.             x_stack += [element[0]]
  76.  
  77.     y_stack = []
  78.  
  79.     for el in stack:
  80.  
  81.         if type(el) == list:
  82.  
  83.             y_stack += [el[0]]
  84.         else:
  85.             y_stack += [el]
  86.  
  87.     for element in y_stack:
  88.  
  89.         if element not in x_stack:
  90.  
  91.             return element
  92.         else:
  93.  
  94.             continue
  95.  
  96.  
  97. arr = list(map(int, input().split()))
  98.  
  99. print(tuple_posibility(arr))
  100.  
Advertisement
Add Comment
Please, Sign In to add comment