Notes in Python - Idiomatic

To Subscribe, use this Key


Status Last Update Fields
Published 05/03/2024 Refactor:x, y, z = [1] *3if x <= y and y <= z:    print True
Published 05/03/2024 Refactor:is_generic_name = Falsename = 'Tom'if name == 'Tom' or name == 'Dick' or name == 'Harry':    is_generic_name = Trueprint is_generic…
Published 05/03/2024 Refactor:foo = Truevalue = 0if foo:    value = 1print(value)
Published 05/03/2024 Refactor to be more readableo = xrange(11)[e + 5 for e in o if e > 4]
Published 05/03/2024 Write a function that check if a list contains a zeroa = [1, 1]e = [1, 0]
Published 05/03/2024 What are extra capabilities of namedtuples?
Published 05/03/2024 print this with format template and named attributesname = 'Eor'animal = 'donkey'age = 4
Published 05/03/2024 if type is one of the following:list, dict, str, tuplea = []
Published 05/03/2024 What is the main advantage of generators?
Published 05/03/2024 Refactor:is_generic_name = Falsename = 'Tom'if name == 'Tom' or name == 'Dick' or name == 'Harry':     is_generic_name = True
Published 05/03/2024 write 'hi' 'there' with 10 spaces chunks center aligned
Published 05/03/2024 Write 'BIG SALE' surrounded by ! #=> '!!!!!!BIG SALE!!!!!!'
Published 05/03/2024 To write to a file, but only if it doesn't exist already:
Published 05/03/2024 Write message to std error
Published 05/03/2024 Raising exceptions with a traceback:
Published 05/03/2024 Exception chaining 
Published 05/03/2024 Test:class FileDatabase:    def __init__(self, filename):        try:            self.file…
Published 05/03/2024 Catching exceptions
Published 05/03/2024 Metaclasses
Published 05/03/2024 Imports relative to a packagemypackage/    __init__.py    submodule1.py    submodule2.pythe code in submodule1.py:
Published 05/03/2024 Iterable dict keys:heights = {'Fred': 175, 'Anne': 166, 'Joe': 192}
Published 05/03/2024 Iterable dict values:heights = {'Fred': 175, 'Anne': 166, 'Joe': 192}
Published 05/03/2024 Iterable dict itemsheights = {'Fred': 175, 'Anne': 166, 'Joe': 192}
Published 05/03/2024 File IO with open()
Published 05/03/2024 Create an iterator, so you call next method on ita = [1, 2, 3]
Published 05/03/2024 # Refactor to use matrix operatorimport numpy as npa = np.array([[1, 0], [0, 1]])b = np.array([[4, 1], [2, 2]])np.dot(a, b)
Published 05/03/2024 Write a one liner to put:- 9 into a - 0-8 into rest
Published 05/03/2024 open text file from interneturl = 'https://www.gutenberg.org/files/38594/38594-0.txt'
Published 05/03/2024 Looping backwardscolors = ['red', 'green', 'blue', 'yellow']
Published 05/03/2024 Unpacking actually works with any object that happens to be _____, not just tuples or lists.
Published 05/03/2024 Find files that .c or .hfilenames = [ 'Makefile', 'foo.c', 'bar.py', 'spam.c', 'spam.h' ]
Published 05/03/2024 Everything in Python is an object and a ___
Published 05/03/2024 dir() == 
Published 05/03/2024 Define a easy to update list
Published 05/03/2024 Hex format strings
Published 05/03/2024 Given a RGB decimal values, convert to a hexadecimal representation.assert rgb(0,0,0) == "000000"assert rgb(1,2,3) == "010203"assert rgb(255…
Published 05/03/2024 find version of python within python
Published 05/03/2024 Only use a list comprehension when ___________,otherwise use a ____________
Status Last Update Fields