Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def merge_tuples(line_a, line_b, line_c):
- """
- funkce merge tuples - spojujici sekvence
- """
- dict = {}
- for tuplik in line_a:
- id = tuplik[0]
- count = tuplik[1]
- list = [count, 0, 0]
- dict[id] = list
- for tuplik in line_b:
- id = tuplik[0]
- count = tuplik[1]
- if id in dict:
- oldList = dict[id]
- else:
- oldList = [0, 0, 0]
- list = [oldList[0], count, oldList[2]]
- dict[id] = list
- for tuplik in line_c:
- id = tuplik[0]
- count = tuplik[1]
- if id in dict:
- oldList = dict[id]
- else:
- oldList = [0, 0, 0]
- list = [oldList[0], oldList[1], count]
- dict[id] = list
- return dict
- if __name__ == '__main__':
- line_a = ((1, 3), (3, 4), (10, 2))
- line_b = ((1, 2), (2, 4), (5, 2))
- line_c = ((1, 5), (3, 2), (7, 3))
- expected_result = {1: [3, 2, 5],
- 2: [0, 4, 0],
- 3: [4, 0, 2],
- 5: [0, 2, 0],
- 7: [0, 0, 3],
- 10: [2, 0, 0]}
- print(expected_result == merge_tuples(line_a, line_b, line_c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement