From a3fba8a04377db93df660bb1de969124f9523e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 23 Apr 2018 03:02:34 +0200 Subject: [PATCH] List, splat, enum --- README.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6c610ae..223aaff 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,10 @@ List ```python sum_of_elements = sum() +elementwise_sum = [sum(pair) for pair in zip(list_a, list_b)] sorted_by_second = sorted(, key=lambda el: el[1]) +sorted_by_both = sorted(, key=lambda el: (el[0], el[1])) flattened_list = [item for sublist in for item in sublist] -elementwise_sum = [sum(pair) for pair in zip(list_a, list_b)] list_of_chars = list() ``` @@ -280,7 +281,7 @@ func(*args, **kwargs) func(1, 2, x=3, y=4, z=5) ``` -**Splat operator can also be used in function declaration:** +**Splat operator can also be used in function declarations:** ```python >>> def add(*a): ... return sum(a) @@ -288,6 +289,13 @@ func(1, 2, x=3, y=4, z=5) 6 ``` +**Or anywhere else:** +```python +>>> a = (1, 2, 3) +>>> [*a] +[1, 2, 3] +``` + Inline ------ ### Lambda @@ -403,10 +411,11 @@ class (enum.Enum): ``` ```python -. # == -(value) # == -.name # == -.value # == +. # == +[''] # == +(value) # == +.name # == +.value # == ``` ```python