Guest User

Untitled

a guest
Oct 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. operator_one = { 1: 'pass',
  2. 2: 'break',
  3. 3: 'print',
  4. 4: 'yield',
  5. 5 :'try' ,
  6. }
  7.  
  8. operator_two = { 1: 'pass',
  9. 2:'global',
  10. 3: 'yield',
  11. 4: 'print',
  12. 5: 'try',
  13. }
  14.  
  15.  
  16. def operator_important(operator_one, operator_two):
  17. """Поиск одинаковых элементов в словаре и словаре и запись в словарь."""
  18. operator_main = {}
  19. for key, values in operator_one.items:
  20. if key, values in operator_two.items:
  21. operator_main[key] = values
  22. return operator_main
  23.  
  24. d = operator_important(operator_one, operator_two)print(d)
  25.  
  26. operator_one = {
  27. 1: 'pass',
  28. 2: 'break',
  29. 3: 'print',
  30. 4: 'yield',
  31. 5: 'try',
  32. }
  33.  
  34. operator_two = {
  35. 1: 'pass',
  36. 2: 'global',
  37. 3: 'yield',
  38. 4: 'print',
  39. 5: 'try',
  40. }
  41.  
  42.  
  43. def operator_important(operator_one, operator_two):
  44. """Поиск одинаковых элементов в словаре и словаре и запись в словарь."""
  45.  
  46. operator_main = dict()
  47. all_keys = set(list(operator_one.keys()) + list(operator_two.keys()))
  48.  
  49. for key in all_keys:
  50. # Если ключ есть в обоих словарях, и значение по ключу одинаковое
  51. if key in operator_one and key in operator_two and operator_one[key] == operator_two[key]:
  52. operator_main[key] = operator_one[key]
  53.  
  54. return operator_main
  55.  
  56. d = operator_important(operator_one, operator_two)
  57. print(d) # {1: 'pass', 5: 'try'}
  58.  
  59. operator_one = { 1: 'pass',
  60. 2: 'break',
  61. 3: 'print',
  62. 4: 'yield',
  63. 5 :'try' ,
  64. }
  65.  
  66. operator_two = { 1: 'pass',
  67. 2:'global',
  68. 3: 'yield',
  69. 4: 'print',
  70. 5: 'try',
  71. }
  72.  
  73. d = {x[0]: y[1] for x, y in zip(operator_one.items(), operator_two.items()) if x == y}
  74. print(d)
Add Comment
Please, Sign In to add comment