set sort python code example

Example 1: orderd set in python

pip install ordered-set
from ordered_set import OrderedSet
letters = OrderedSet('abracadabra')
print(letters) # {'a', 'b', 'r', 'c', 'd'}

Example 2: python sort

>>> student_tuples = [
...     ('john', 'A', 15),
...     ('jane', 'B', 12),
...     ('dave', 'B', 10),
... ]
>>> sorted(student_tuples, key=lambda student: student[2])   # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

Example 3: sorted list python

sorted(iterable, key=None, reverse=False)

type(sorted(iterable, key=None, reverse=False)) = list