From 404b3ccdbbf88a9ce4826ff758c74b38d085facb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 18 Apr 2018 01:58:55 +0200 Subject: [PATCH] Dict --- README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cde6cf9..b806c15 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,9 @@ List sum() sorted_by_second = sorted(, key=lambda el: el[1]) flattened_list = [item for sublist in for item in sublist] +list() # Creates list of chars. ``` -```python ->>> list('ABC') -['A', 'B', 'C'] -``` Dictionary ---------- @@ -43,17 +40,18 @@ Dictionary .update() ``` +```python +>>> a = [('x', 4), ('y', 5)] +>>> dict(a) +{'x': 4, 'y': 5} +``` + ```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 .items() if k in } # Filters a dict by keys. ``` -```python ->>> a = [('x', 4), ('y', 5)] ->>> dict(a) -{'x': 4, 'y': 5} -``` ### Counter ```python