Skip to content

Instantly share code, notes, and snippets.

@makwanadeepam
Created March 27, 2024 18:41
Show Gist options
  • Save makwanadeepam/330e4a6fbd4ba7a8fed78d18e148b8d5 to your computer and use it in GitHub Desktop.
Save makwanadeepam/330e4a6fbd4ba7a8fed78d18e148b8d5 to your computer and use it in GitHub Desktop.
s: set={1,2,3,4,5,55,5}
print(s)
# for loop
for i in s:
print(i)
# add, remove, clear, discard
s.add(33)
print(s)
s.remove(4)
print(s)
s.clear()
print(s)
s={1,2,3,4,5,55}
s1={2,3,4}
print(s.difference(s1))
s.discard(55) # Doesn't raise error if element doesn't exist
print(s)
# union intersection
print(s.intersection(s1))
print(s.union(s1))
# membership and pop
print(5 in s)
s.pop() # Takes no arguments
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment