-
-
Save keefo/1b54dd5bbe1f5d5df62cef156ef41616 to your computer and use it in GitHub Desktop.
Merge arrays with duplicated elements
This file contains hidden or 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