From 65890ab295d4668883f6b57eb95e31b7df4800cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 28 Nov 2018 17:21:10 +0100 Subject: [PATCH] bla --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2edead0..2a71347 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ sorted_by_second = sorted(, key=lambda el: el[1]) sorted_by_both = sorted(, key=lambda el: (el[1], el[0])) flattened_list = [item for sublist in for item in sublist] list_of_chars = list() +product_of_els = functools.reduce(lambda out, x: out * x, ) ``` ```python @@ -100,7 +101,8 @@ range(from_inclusive, to_exclusive, -step_size) Enumerate --------- ```python -for i, in enumerate( [, i_start]) +for i, in enumerate( [, i_start]): + ... ``` Named Tuple @@ -408,10 +410,10 @@ from enum import Enum Direction = Enum('Direction', 'n e s w') Cutlery = Enum('Cutlery', {'knife': 1, 'fork': 2, 'spoon': 3}) +# Warrning: Objects will share the objects that are initialized in the dict! Creature = type('Creature', (), {'position': Point(0, 0), 'direction': Direction.n}) ``` - Closure ------- ```python @@ -498,11 +500,15 @@ class (Enum): ``` ```python -Cutlery = Enum('Cutlery', 'knife', 'fork', 'spoon']) +Cutlery = Enum('Cutlery', ['knife', 'fork', 'spoon']) Cutlery = Enum('Cutlery', 'knife fork spoon') Cutlery = Enum('Cutlery', {'knife': 1, 'fork': 2, 'spoon': 3}) -list() # == [, , ...] -random.choice(list()) # == random +# Functions can not be values, so they must be enclosed in tuple: +LogicOp = Enum('LogicOp', {'AND': (lambda l, r: l and r, ), + 'OR' : (lambda l, r: l or r, ), +list() # == [, , ...] +list(a.name for a in ) # == ['enum1', 'enum2', ...] +random.choice(list()) # == random ``` ### Copy @@ -803,7 +809,7 @@ from itertools import * ``` ### Ifilter, imap and izip -#### Filter, map and zip functions that return generators instead of iterators. +#### Filter, map and zip functions that return generators instead of iterators. Droped in Pyhon 3, because filter, map and zip functions started returning generators. Introspection and Metaprograming