Skip to content

Instantly share code, notes, and snippets.

@LIQRGV
Created January 9, 2020 02:15
Show Gist options
  • Save LIQRGV/894c46c200b15e77f3c6ffb4005a5ebb to your computer and use it in GitHub Desktop.
Save LIQRGV/894c46c200b15e77f3c6ffb4005a5ebb to your computer and use it in GitHub Desktop.
#Implement the unique_names method. When passed two arrays of names, it will return an array containing the names that appear in either or both arrays. The returned array should have no duplicates.
#For example, calling unique_names(['Ava', 'Emma', 'Olivia'], ['Olivia', 'Sophia', 'Emma']) should return an array containing Ava, Emma, Olivia, and Sophia in any order.
#https://www.testdome.com/questions/python/merge-names/24231?visibility=1&skillId=9
def unique_names(names1, names2):
unique_list = lambda input_var: list(set(input_var))
return unique_list(names1) + [name for name in unique_list(names2) if name not in names1]
names1 = ["Ava", "Emma", "Olivia"]
names2 = ["Olivia", "Sophia", "Emma"]
print(unique_names(names1, names2)) # should print ['Ava', 'Emma', 'Olivia', 'Sophia']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment