Skip to content

Instantly share code, notes, and snippets.

@frendhisaido
Created July 24, 2021 17:41
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 frendhisaido/e5084bc4f921c3a4c36445b9d6d71c09 to your computer and use it in GitHub Desktop.
Save frendhisaido/e5084bc4f921c3a4c36445b9d6d71c09 to your computer and use it in GitHub Desktop.
JDS BI_DEV_Python
def unique_names(names1, names2):
# rubah ke set, dan jadi unique values
first_set = set(names1)
second_set = set(names2)
second_only = second_set - first_set # yang cuma ada di list kedua
combined = names1 + list(second_only) # gabung lagi sama yg pertama
unique_list = list(set(combined)) # pastiin unique buat edge cases di tiap list ada duplikat
return unique_list
names1 = ["Ava", "Emma", "Olivia","Ava"]
names2 = ["Olivia", "Sophia", "Emma", "Sophia"]
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