diff --git a/README.md b/README.md index 362b03a..bd5f35f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ List ```python sum() -sorted_by_second = sorted(, key=lambda tup: tup[1]) +sorted_by_second = sorted(, key=lambda el: el[1]) flattened_list = [item for sublist in for item in sublist] ``` @@ -64,7 +64,7 @@ Set ### Frozenset #### Is hashable and can be used as a key in dictionary: ```python - = frozenset() + = frozenset() ``` Range @@ -85,12 +85,12 @@ for i, in enumerate( [, i_start]) Named Tuple ----------- ```python ->>> TestResults = collections.namedtuple('TestResults', ['filed', 'attempted']) ->>> a = TestResults(1, attempted=2) -TestResults(filed=1, attempted=2) ->>> a.filed +>>> Point = collections.namedtuple('Point', ['x', 'y']) +>>> a = Point(1, y=2) +Point(x=1, y=2) +>>> a.x 1 ->>> getattr(a, 'attempted') +>>> getattr(a, 'y') 2 ``` @@ -134,7 +134,7 @@ next(stepper) # 10 (, 12, 14, ...) Type ---- ```python -type() # //... +type() # / / ... ``` ```python import numbers @@ -163,14 +163,13 @@ print( [, , end='', sep='', file=]) import re re.sub(, new, text, count=0) re.search(, text) # Searches for first occurrence of pattern. -re.match(, text) # Searches only at the beginning of the string. +re.match(, text) # Searches only at the beginning of the string. re.findall(, text) re.split(, text, maxsplit=0) # Use brackets in regex to keep the matches. ``` -**'Search' and 'match' functions return a 'Match' object. Use '.group()' method on it to get the match.** -**Parameter 'flags=re.IGNORECASE' can be used with all functions.** -**Parameter 'flags=re.DOTALL' makes dot also accept newline.** +**'Search' and 'match' functions return a 'Match' object. Use '.group()' method on it to get the whole match, or '.group(1)' to get the part in first bracket.** +**Parameter 'flags=re.IGNORECASE' can be used with all functions. Parameter 'flags=re.DOTALL' makes dot also accept newline.** **Use '\\\\1' or r'\1' for backreference.** #### Special Sequences: