Back to the page

In the print window, choose “Save as PDF”.

doubtly doubtly.in

Set & List Comprehension’s in Python

Python · Updated 1 Jul 2024 · Read online: www.doubtly.in/set-list-comprehensions-in-python/

Set & List Comprehension’s in Python

Sets

:-

my_set.remove(3)    # Raises KeyError if element notfound
my_set.discard(3)   # Does nothing if element not found
my_set.clear()      # Removes all elements

set operations

Advanced List

eg : sqaures = [x*x for x in range(0,9) if x%2 == 0]

[[1,2],[3,4]]

list.copy() list.deepcopy()

Practise this on Doubtly (free)