Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. def merge_tuples(line_a, line_b, line_c):
  2. """
  3. funkce merge tuples - spojujici sekvence
  4. """
  5.  
  6. dict = {}
  7.  
  8. for tuplik in line_a:
  9. id = tuplik[0]
  10. count = tuplik[1]
  11. list = [count, 0, 0]
  12. dict[id] = list
  13.  
  14. for tuplik in line_b:
  15. id = tuplik[0]
  16. count = tuplik[1]
  17.  
  18. if id in dict:
  19. oldList = dict[id]
  20. else:
  21. oldList = [0, 0, 0]
  22.  
  23. list = [oldList[0], count, oldList[2]]
  24. dict[id] = list
  25.  
  26. for tuplik in line_c:
  27. id = tuplik[0]
  28. count = tuplik[1]
  29.  
  30. if id in dict:
  31. oldList = dict[id]
  32. else:
  33. oldList = [0, 0, 0]
  34.  
  35. list = [oldList[0], oldList[1], count]
  36. dict[id] = list
  37.  
  38. return dict
  39.  
  40. if __name__ == '__main__':
  41.  
  42. line_a = ((1, 3), (3, 4), (10, 2))
  43. line_b = ((1, 2), (2, 4), (5, 2))
  44. line_c = ((1, 5), (3, 2), (7, 3))
  45.  
  46. expected_result = {1: [3, 2, 5],
  47. 2: [0, 4, 0],
  48. 3: [4, 0, 2],
  49. 5: [0, 2, 0],
  50. 7: [0, 0, 3],
  51. 10: [2, 0, 0]}
  52.  
  53. print(expected_result == merge_tuples(line_a, line_b, line_c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement