Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> ntice = ( ... 666, ... [1, 2, 'a'], ... 'ahoj', ... ) >>> ntice 0: (666, [1, 2, 'a'], 'ahoj') >>> type(ntice) 1: <class 'tuple'> >>> ntice[1] 2: [1, 2, 'a'] >>> hash(ntice) Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> hash(ntice) TypeError: unhashable type: 'list' >>> ntice[1][-1] 3: 'a' >>> ntice[1][-1] = 333 >>> ntice 4: (666, [1, 2, 333], 'ahoj') >>> ntice[1].append('baf') >>> ntice 5: (666, [1, 2, 333, 'baf'], 'ahoj') >>> ntice[1].extend('abc') >>> ntice 6: (666, [1, 2, 333, 'baf', 'a', 'b', 'c'], 'ahoj') >>> ntice[1] += [123] Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> ntice[1] += [123] TypeError: 'tuple' object does not support item assignment >>> ntice 7: (666, [1, 2, 333, 'baf', 'a', 'b', 'c', 123], 'ahoj') >>> ntice[1] += [(123,)] Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> ntice[1] += [(123,)] TypeError: 'tuple' object does not support item assignment >>> ntice 8: (666, [1, 2, 333, 'baf', 'a', 'b', 'c', 123, (123,)], 'ahoj') >>> ntice[1][-1] 9: (123,) >>> type(ntice[1][-1]) 10: <class 'tuple'> >>> dir(ntice[1][-1]) 11: ['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index'] [About 33 more lines. Double-click to unfold] >>> import string >>> dir(string) 12: ['Formatter', 'Template', '_ChainMap', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_re', '_sentinel_dict', '_string', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'capwords', 'digits', 'hexdigits', 'octdigits', 'printable', 'punctuation', 'whitespace'] >>> string.ascii_lowercase 13: 'abcdefghijklmnopqrstuvwxyz' >>> string.digits 14: '0123456789' >>> string.punctuation 15: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' >>> string.printable 16: ('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n' '\r' '\x0b' '\x0c') >>> string.punctuation 17: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' >>> string.whitespace 18: ' \t\n\r\x0b\x0c' >>> string.printable[10:] 19: ('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n' '\r' '\x0b' '\x0c') >>> xs = list('ahoj') >>> xs 20: ['a', 'h', 'o', 'j'] >>> ys = [] >>> ys = [] ... for prvek in xs: ... ys.append(ord(prvek)) >>> ys 21: [97, 104, 111, 106] >>> zs = [ord(prvek) for prvek in xs] >>> zs 22: [97, 104, 111, 106] >>> ys = [] ... for prvek in xs: ... o = ord(prvek) ... if o >= 100: ... ys.append(o) >>> ys 23: [104, 111, 106] >>> zs = [ord(prvek) for prvek in xs if ord(prvek) >= 100] >>> zs 24: [104, 111, 106] >>> prvek 25: 'j' >>> xs 26: ['a', 'h', 'o', 'j'] >>> zs = [ord(x) for x in xs if ord(x) >= 100] >>> x Traceback (most recent call last): File "<pyshell#42>", line 1, in <module> x NameError: name 'x' is not defined >>> zs = [o for x in xs if (o := ord(x)) >= 100] >>> zs 27: [104, 111, 106] >>> zs = [o for x in xs if (o := ord(x)) < 100] >>> zs 28: [97] >>> '\t'.join(('symbol', 'mass', 'ord', 'en', 'els', 'valency')) 29: 'symbol\tmass\tord\ten\tels\tvalency' >>> '|'.join(('symbol', 'mass', 'ord', 'en', 'els', 'valency')) 30: 'symbol|mass|ord|en|els|valency' >>> xs = [1, 2, 3, 4, 5] >>> xs[3] = [666] >>> xs 31: [1, 2, 3, [666], 5] >>> xs[3:] 32: [[666], 5] >>> xs[3:] = ['a', 333, print] >>> xs 33: [1, 2, 3, 'a', 333, <built-in function print>] >>> xs[-1] 34: <built-in function print> >>> xs[-1](2 + 3) 5 >>> xs 35: [1, 2, 3, 'a', 333, <built-in function print>] >>> del xs[3:] >>> xs 36: [1, 2, 3] >>> xs.append(['a', 'b', 'c']) >>> xs 37: [1, 2, 3, ['a', 'b', 'c']] >>> len(xs) 38: 4 >>> xs[-1] 39: ['a', 'b', 'c'] >>> xs.extend(['a', 'b', 'c']) >>> xs 40: [1, 2, 3, ['a', 'b', 'c'], 'a', 'b', 'c'] >>> len(xs) 41: 7 >>> xs.extend('6789') >>> xs 42: [1, 2, 3, ['a', 'b', 'c'], 'a', 'b', 'c', '6', '7', '8', '9'] >>> del xs[3:] >>> xs 43: [1, 2, 3] >>> xs += 'abc' >>> xs 44: [1, 2, 3, 'a', 'b', 'c'] >>> xs = ['jedna', 'dvě', 'tři', 'čtyři', 'pět', 'šest', 'sedm'] >>> id(xs) 45: 2809489046848 >>> xs.sort() >>> xs 46: ['dvě', 'jedna', 'pět', 'sedm', 'tři', 'čtyři', 'šest'] >>> id(xs) 47: 2809489046848 >>> names = [ "John", "Wendy", "Pete", "Jane", "David", "Amanda", "Ix"] >>> names.sort() >>> names 48: ['Amanda', 'David', 'Ix', 'Jane', 'John', 'Pete', 'Wendy'] >>> names.sort(key=len) >>> names 49: ['Ix', 'Jane', 'John', 'Pete', 'David', 'Wendy', 'Amanda'] >>> names = [ "John", "Wendy", "Pete", "Jane", "David", "Amanda", "Ix"] >>> names.sort(key=len) >>> names 50: ['Ix', 'John', 'Pete', 'Jane', 'Wendy', 'David', 'Amanda'] >>> len(names) 51: 7 >>> ['!' for x in names] 52: ['!', '!', '!', '!', '!', '!', '!'] >>> xs = [1, 2, 3] ... ys = ['a', 'b', 'c'] ... [(x, y) for x in xs for y in ys] 53: [(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'), (2, 'b'), (2, 'c'), (3, 'a'), (3, 'b'), (3, 'c')] >>> xs = [1, 2, 3] ... ys = ['a', 'b', 'c'] ... [(x, y) for x in ys for y in xs] 54: [('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3), ('c', 1), ('c', 2), ('c', 3)] >>> xs = [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9], ... ] >>> xs 55: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> len(xs) 56: 3 >>> xs[1] 57: [4, 5, 6] >>> xs[1][-1] 58: 6 >>> xs[1][-1] = 'A' >>> xs 59: [[1, 2, 3], [4, 5, 'A'], [7, 8, 9]] >>> [[0, 0, 0]]*3 60: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>> xs = [[0, 0, 0]]*3 >>> xs 61: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>> xs[1] 62: [0, 0, 0] >>> xs[1][-1] 63: 0 >>> xs[1][-1] = 'A' >>> xs 64: [[0, 0, 'A'], [0, 0, 'A'], [0, 0, 'A']] >>> xs = [[0, 0, 0] for i in range(3)] >>> xs 65: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>> xs[1][-1] = 'A' >>> xs 66: [[0, 0, 0], [0, 0, 'A'], [0, 0, 0]] >>> eval('(1,3,5,7)') 67: (1, 3, 5, 7) >>> x = eval('(1,3,5,7)') >>> x 68: (1, 3, 5, 7) >>> type(x) 69: <class 'tuple'> >>> for x in 'ahoj': ... print(x) a h o j >>> for x in zip('ahoj', [1, 2, 3, 4]): ... print(x) ('a', 1) ('h', 2) ('o', 3) ('j', 4) >>> for x in zip('ahoj', [1, 2, 3, 4], 'zyxw'): ... print(x) ('a', 1, 'z') ('h', 2, 'y') ('o', 3, 'x') ('j', 4, 'w') >>> for x in zip('ahoj', [1, 2, 3, 4], 'zyxwv'): ... print(x) ('a', 1, 'z') ('h', 2, 'y') ('o', 3, 'x') ('j', 4, 'w') >>> from itertools import zip_longest >>> for x in zip_longest('ahoj', [1, 2, 3, 4], 'zyxwv'): ... print(x) ('a', 1, 'z') ('h', 2, 'y') ('o', 3, 'x') ('j', 4, 'w') (None, None, 'v') >>> for x in zip_longest('ahoj', [1, 2, 3, 4], 'zyxwv', fillvalue='!'): ... print(x) ('a', 1, 'z') ('h', 2, 'y') ('o', 3, 'x') ('j', 4, 'w') ('!', '!', 'v') >>>