From abfabfe8a9c820df93787ab12f36963c94f6ad6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 14 Mar 2018 17:22:39 +0100 Subject: [PATCH] Update --- README.md | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ba6d84a..e4babae 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,12 @@ List .extend() .sort() .reverse() +``` + +```python sum() sorted_by_second = sorted(, key=lambda tup: tup[1]) -[item for sublist in for item in sublist] # Flattens List +[item for sublist in for item in sublist] # Flattens List. ``` Dictionary @@ -28,9 +31,12 @@ Dictionary .get(key, default) .setdefault(key, default) .update() -collections.defaultdict() -dict(zip(keys, values)) # Initiates a dict from two lists -{k: v for k, v in .iteritems() if k in } # Filters a dict by keys +``` + +```python +collections.defaultdict() # Creates a dictionary with default values. +dict(zip(keys, values)) # Initiates a dict from two lists. +{k: v for k, v in .iteritems() if k in } # Filters a dict by keys. ``` #### Counter @@ -50,7 +56,7 @@ Set .union() .intersection() .difference() - # Is hashable and can be used as key in dictionary + # Is hashable and can be used as key in dictionary. ``` Range @@ -58,7 +64,7 @@ Range ```python range(to_exclusive) range(from_inclusive, to_exclusive) -range(from_inclusive, to_exclusive, step_size) # Negative step for backward +range(from_inclusive, to_exclusive, step_size) # Negative step_size for backward ``` Enumerate @@ -98,16 +104,17 @@ def step(start, step): while True: yield start start += step - +``` +```python stepper = step(10, 2) -next(stepper) # -> 10 (, 12, 14, ...) +next(stepper) # 10 (, 12, 14, ...) ``` Type ---- ```python -type() # is int/str/set/list/... +type() # int/str/set/list/... ``` ```python import numbers @@ -139,17 +146,17 @@ re.search(, text) ### Format ```python -'{}'.format() +'{}'.format( [, , ...]) ``` ```python -{:min_width} # -> ' ' -{:>min_width} # -> ' ' -{:^min_width} # -> ' ' -{:_min_width} # -> '____' -{:.max_width} # -> '' -{:max_widht.min_width} # -> ' ' -{:max_width.no_of_decimalsf} # -> ' 3.14' +{:min_width} # ' ' +{:>min_width} # ' ' +{:^min_width} # ' ' +{:_min_width} # '____' +{:.max_width} # '' +{:max_widht.min_width} # ' ' +{:max_width.no_of_decimalsf} # ' 3.14' ``` ```python @@ -198,16 +205,15 @@ func(*args, **kwargs) # Is same as func(1, 2, x=3, y=4, z=5) ``` -##### "*" is the "splat" operator, that takes a list as input, and expands it -into actual positional arguments in the function call. +#### "*" is the splat operator, that takes a list as input, and expands it into actual positional arguments in the function call. Inline ------ ### Lambda ```python -lambda , : -lambda: +lambda , : +lambda: ``` ### Comprehension