Common Operations¶
There are some functions which can be applied on all collections. Here we will see details related to list
and set
.
in
- check if element existslen
- to get the number of elements.sorted
- to sort the data (original collection will be untouched). Typically, we assign the result of sorting to a new collection.sum
,min
,max
, etc - arithmetic operations.There can be more such functions.
l = [1, 2, 3, 4] # list
1 in l
True
5 in l
False
len(l)
4
sorted(l)
[1, 2, 3, 4]
sum(l)
10
s = {1, 2, 3, 4} # set
1 in s
True
5 in s
False
len(s)
4
sorted(s)
[1, 2, 3, 4]
sum(s)
10