Created
July 24, 2021 17:41
-
-
Save frendhisaido/e5084bc4f921c3a4c36445b9d6d71c09 to your computer and use it in GitHub Desktop.
JDS BI_DEV_Python
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 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