Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> ds = { 'a': 'ahoj', 123: 'svět', (12, 'fokus'): 666, } >>> ds 0: {123: 'svět', 'a': 'ahoj', (12, 'fokus'): 666} >>> ds[(12, 'fokus')] 1: 666 >>> ds[12, 'fokus'] 2: 666 >>> len(ds) 3: 3 >>> 'a' in ds 4: True >>> ds['a'] 5: 'ahoj' >>> ds['b'] Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> ds['b'] ~~^^^^^ KeyError: 'b' >>> for k in ds: ... print(k) a 123 (12, 'fokus') >>> for k in ds.keys(): ... print(k) a 123 (12, 'fokus') >>> for k in ds.values(): ... print(k) ahoj svět 666 >>> for k in ds: ... print(k, ds[k]) a ahoj 123 svět (12, 'fokus') 666 >>> for k in ds.items(): ... print(k) ('a', 'ahoj') (123, 'svět') ((12, 'fokus'), 666) >>> for k,v in ds.items(): ... print(k, v, sep=' | ') a | ahoj 123 | svět (12, 'fokus') | 666 >>> for k in reversed(ds): ... print(k, ds[k]) (12, 'fokus') 666 123 svět a ahoj >>> for k in sorted(ds): ... print(k, ds[k]) Traceback (most recent call last): File "<pyshell#15>", line 1, in <module> for k in sorted(ds): ^^^^^^^^^^ TypeError: '<' not supported between instances of 'int' and 'str' >>> ds.get('a') 6: 'ahoj' >>> ds.get('b') >>> print(ds.get('b')) None >>> ds.get('b', 'Baf!') 7: 'Baf!' >>> ds 8: {123: 'svět', 'a': 'ahoj', (12, 'fokus'): 666} >>> ds.popitem() 9: ((12, 'fokus'), 666) >>> xs = ['a', 'b', 'c'] >>> zs = { 1: xs } >>> from copy import deepcopy >>> zs2 = deepcopy(zs) >>> zs 10: {1: ['a', 'b', 'c']} >>> zs2 11: {1: ['a', 'b', 'c']} >>> xs.pop() 12: 'c' >>> xs 13: ['a', 'b'] >>> zs 14: {1: ['a', 'b']} >>> zs2 15: {1: ['a', 'b', 'c']} >>> ds = { 'c': "ahoj", 'a': 1, 'b': [1,2,3], } >>> ds 16: {'a': 1, 'b': [1, 2, 3], 'c': 'ahoj'} >>> id(zs) 17: 2797346821568 >>> id(zs2) 18: 2797346680384 >>> zs3 = zs >>> id(zs3) 19: 2797346821568 >>> xs = {1, 2, 3} >>> type(xs) 20: <class 'set'> >>> xs = {1, 2, 'abc'} >>> type(xs) 21: <class 'set'> >>> xs = {1, 2, [1, 2, 3]} Traceback (most recent call last): File "<pyshell#42>", line 1, in <module> xs = {1, 2, [1, 2, 3]} ^^^^^^^^^^^^^^^^^ TypeError: unhashable type: 'list' >>> def fn(): ... pass >>> xs = {1, 2, fn} >>> type(xs) 22: <class 'set'> >>> xs 23: {<function fn at 0x0000028B4EDDBB00>, 1, 2} >>> for x in 'abc': ... print(x) a b c >>> for x in zip('abc', 'def'): ... print(x) ('a', 'd') ('b', 'e') ('c', 'f') >>> for x in zip('abc', 'defgh'): ... print(x) ('a', 'd') ('b', 'e') ('c', 'f') >>> from itertools import zip_longest >>> for x in zip_longest('abc', 'defgh'): ... print(x) ('a', 'd') ('b', 'e') ('c', 'f') (None, 'g') (None, 'h') >>> for x in zip_longest('abc', 'defgh', default=666): ... print(x) Traceback (most recent call last): File "<pyshell#52>", line 1, in <module> for x in zip_longest('abc', 'defgh', default=666): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: zip_longest() got an unexpected keyword argument >>> for x in zip_longest('abc', 'defgh', fill_value=666): ... print(x) Traceback (most recent call last): File "<pyshell#53>", line 1, in <module> for x in zip_longest('abc', 'defgh', fill_value=666): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: zip_longest() got an unexpected keyword argument >>> for x in zip_longest('abc', 'defgh', fillvalue=666): ... print(x) ('a', 'd') ('b', 'e') ('c', 'f') (666, 'g') (666, 'h') >>> for x in zip('abc', 'defgh', [1, 2, 3]): ... print(x) ('a', 'd', 1) ('b', 'e', 2) ('c', 'f', 3) >>> from itertools import tee >>> for x in tee('abcdefgh', 2): ... print(x) <itertools._tee object at 0x0000028B4EE09E00> <itertools._tee object at 0x0000028B4EE09C40> >>> x, y = tee('abcdefgh', 2) >>> for i in x: print(i) a b c d e f g h >>> for i in y: print(i) a b c d e f g h >>> ds 24: {'a': 1, 'b': [1, 2, 3], 'c': 'ahoj'} >>> set(ds) 25: {'a', 'c', 'b'} >>> int() 26: 0 >>> float() 27: 0.0 >>> list() 28: [] >>> set() 29: set() >>> dict() 30: {} >>> xs = "abrakadabra" >>> from collections import Counter >>> Counter(xs) 31: Counter({'a': 5, 'b': 2, 'r': 2, 'k': 1, 'd': 1}) >>>