kuniga.me > Docs > Python Cheatsheet
Syntax for common tasks I run into often. Assumes Python 3.
- Map over list
- Filter list
- Sort list
- Map over dictionary
- Sort dictionary
- Map over set
- Object Oriented
- Read file
- Other Data Structures
Map over list
NOTE: filter and map can be combined into one.
Using default sorting:
Sorting using key function. For example, sort list of pairs by the second element:
Sorting by custom comparator:
Map over dictionary
Dictionaries are unordered sets, so you likely want to work with a list after sorting.
Map over set
Check if object is instance of a class:
Lightweight syntax for creating classes / records.
Other Data Structures
Queue class is an advanced implementation that can be used for example in multi-thread applications. We can still use it as a plain queue data structure.