From 51e8fcef922fae90fc43e7baa65b9b077c3dc8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 14 Mar 2018 06:13:12 +0100 Subject: [PATCH] Update --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c2a0640..87a4d96 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ if __name__ == '__main__': List ---- ```python -[::] +[::] .extend() .sort() .reverse() @@ -20,8 +20,8 @@ sum() sorted_by_second = sorted(, key=lambda tup: tup[1]) ``` -Flatten List -``` +#### Flatten List +```python [item for sublist in list for item in sublist] ``` @@ -36,17 +36,17 @@ collections.defaultdict() # Creates list ``` Init from two lists -``` +```python dict(zip(keys, values)) ``` Filter by keys -``` +```python {k: v for k, v in d.iteritems() if k in [2,3]} ``` Counter -``` +```python >>> from collections import Counter >>> z = ['blue', 'red', 'blue', 'yellow', 'blue', 'red'] >>> Counter(z) @@ -81,7 +81,7 @@ for i, in enumerate(, [start]) Named Tuples ------------ -``` +```python >>> TestResults = collections.namedtuple('TestResults', ['filed', 'attempted']) >>> TestResults(1, 2) TestResults(filed=1, attempted=2) @@ -91,14 +91,14 @@ TestResults(filed=1, attempted=2) Iterator -------- Reads input until it reaches empty line. -``` +```python for line in iter(input, ''): print(line) ``` Use partial from functools if function needs arguments. Skips first element. -``` +```python next() for element in : ...