Subcategory: None · Core

List Comprehension

List comprehension (e.g. [expression for item in iterable if condition == True]) is faster than constructing a list with a loop. it can’t be used for all list construction, such as where items depend on one another, but it should be used whenever possible.

Read More

Set

Similar to the mathematical concept of a set, Python (and most other languages) provides a data structure set which is an unordered collection of unique values. Using a set is the fastest way to detect unique items (e.g. if a in my_set) or remove duplicates (e.g. [x for x in set(my_list)]).

Read More