Skip to content

Instantly share code, notes, and snippets.

@ItsCosmas
Created May 8, 2019 20:27
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 ItsCosmas/8caead7dd66ffd9ada552ff09c556ee5 to your computer and use it in GitHub Desktop.
Save ItsCosmas/8caead7dd66ffd9ada552ff09c556ee5 to your computer and use it in GitHub Desktop.
Sets
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