Python

[Issues] List

Change Value in List Based on Conditions E.g. 1 >>> a = ["a", "b", "c", "d", "e"] >>> b = ["a", "c", "e"] We want a list vector with the same length as a.

2020-07-08

Documenting Python Code

Source: Documenting Python Code: A Complete Guide Commenting vs. Documenting Code Description Audience Commenting Purpose and design of code Maintainers and developers Documenting Use and functionality of code Users Commenting Code Comments are created in Python using the pound sign (#) and should be brief statements no longer than a few sentences.

2020-07-06

Beautiful Python Code with PEP 8

Source: How to Write Beautiful Python Code With PEP 8 Naming Conventions “Explicit is better than implicit.” — The Zen of Python ‼️ Note: Never use l (\ell), O (zero), or I (capital i) single letter names as these can be mistaken for 1 and 0, depending on typeface:

2020-07-06

zip

zip(): creates an iterator that will aggregate elements from two or more iterables. According to the official documentation, Python’s zip() function behaves as follows: Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.

2020-07-06

args and kwargs

Passing multiple arguments to a function *args and **kwargs allow you to pass multiple arguments or keyword arguments to a function. args will collect extra positional arguments as a tuple because the parameter name has a * prefix.

2020-07-06

Namedtuple

TL;DR collection.namedtuple is a memory-efficient shortcut to defining an immutable class in Python manually. Namedtuples can help clean up your code by enforcing an easier to understand structure on your data, which also improves readability.

2020-05-02

Underscores in Python

TL;DR Pattern Example Meaning Single Leading Underscore _var Naming convention indicating a name is meant for internal use. Generally not enforced by the Python interpreter (except in wildcard imports) and meant as a hint to the programmer only.

2020-05-01