Skip to content

Instantly share code, notes, and snippets.

@eduzen
Created July 7, 2019 17:13
Show Gist options
  • Save eduzen/86c8335e88b7933a778508dbe0ef502a to your computer and use it in GitHub Desktop.
Save eduzen/86c8335e88b7933a778508dbe0ef502a to your computer and use it in GitHub Desktop.
Merge arrays with duplicated elements
def merge_lists(aList, bList):
if not aList or not bList:
print("empty lists")
return aList + bList
c = []
while aList and bList:
if aList[0] < bList[0]:
c.append(aList.pop(0))
else:
c.append(bList.pop(0))
return c + aList + bList
def main():
lista1 = [0,3,7,9,10]
lista2 = [-1, 0, 3, 18, 20]
print(lista1, lista2)
result = merge_lists(lista1, lista2)
print(result)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment