Skip to content

Instantly share code, notes, and snippets.

@arsho
Created May 19, 2019 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arsho/933c12171f6e0c6d05622f83f671b74d to your computer and use it in GitHub Desktop.
Save arsho/933c12171f6e0c6d05622f83f671b74d to your computer and use it in GitHub Desktop.
Shanto mapping debug
def merge_two_lists(a, b):
data = {}
for pair in a+b:
key, value = pair
data[key] = data.get(key, 0) + value
sorted_data = sorted([[key, value] for key, value in data.items()])
return sorted_data
if __name__ == '__main__':
a = [['hello', 5], ['test', 6], ['egg', 2]]
b = [['cat', 5], ['dog', 6], ['hello', 3], ['test', 2]]
sorted_data = merge_two_lists(a, b)
print(sorted_data)
# Output: [['cat', 5], ['dog', 6], ['egg', 2], ['hello', 8], ['test', 8]]
# The following section is for testing
expected_result = sorted([['hello', 8],
['test', 8],
['cat', 5],
['dog', 6],
['egg', 2]])
assert sorted_data == expected_result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment