Created
July 7, 2019 17:13
-
-
Save eduzen/86c8335e88b7933a778508dbe0ef502a to your computer and use it in GitHub Desktop.
Merge arrays with duplicated elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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