Created
May 8, 2019 20:27
-
-
Save ItsCosmas/8caead7dd66ffd9ada552ff09c556ee5 to your computer and use it in GitHub Desktop.
Sets
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
my_set = {"apple", "banana", "cherry", "strawberry", "grapes"} | |
# removes an element from the set | |
my_set.discard("banana") | |
print(my_set) | |
# Clear empties the set | |
my_set.clear() | |
print(my_set) | |
# set constructor is used to create a set | |
a_set = set(("apple", "banana", "cherry")) | |
print(a_set) | |
duplicate_list = [5, 9, 10, 10, 11, 11, 5, 6, 9, 9, 12] | |
unduplicated_list = list(set(duplicate_list)) | |
print(unduplicated_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment