Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
DreamPie 1.2.1
>>> xs = list(range(10))
>>> xs
0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> len(xs)
1: 10
>>> x = xs
>>> x
2: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x, y, *_ = xs
>>> x
3: 0
>>> y
4: 1
>>> _
5: 1
>>> x, y, *z = xs
>>> z
6: [2, 3, 4, 5, 6, 7, 8, 9]
>>> z
7: [2, 3, 4, 5, 6, 7, 8, 9]
>>> x
8: 0
>>> y
9: 1
>>> z
10: [2, 3, 4, 5, 6, 7, 8, 9]
>>> *x, y, z = xs
>>> x
11: [0, 1, 2, 3, 4, 5, 6, 7]
>>> y
12: 8
>>> z
13: 9
>>> x, *y, z = xs
>>> x
14: 0
>>> y
15: [1, 2, 3, 4, 5, 6, 7, 8]
>>> z
16: 9
>>> x, y, z, z, *z = xs
>>> x
17: 0
>>> y
18: 1
>>> z
19: [4, 5, 6, 7, 8, 9]
>>> x, y, _, _, *z = xs
>>> x
20: 0
>>> y
21: 1
>>> z
22: [4, 5, 6, 7, 8, 9]
>>> x, y, _, _, *z = xs
>>> _
23: 3
>>> _
24: 3
>>> *x, = xs
>>> x
25: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> xs = ['Ahoj!', 123, (12, 'tři'), ['hokus', 'pokus'], 'lokus 666']
>>> (12, 'tři') in xs
26: True
>>> 12, 'tři' in xs
27: (12, False)
>>> (12, 'tři' in xs)
28: (12, False)
>>> dir(xs)
29: ['__add__',
'__class__',
'__class_getitem__',
'__contains__',
'__delattr__',
'__delitem__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__getstate__',
'__gt__',
'__hash__',
'__iadd__',
'__imul__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__mul__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__reversed__',
'__rmul__',
'__setattr__',
'__setitem__',
'__sizeof__',
'__str__',
'__subclasshook__',
'append',
'clear',
'copy',
'count',
'extend',
'index',
'insert',
'pop',
'remove',
'reverse',
'sort']
[About 47 more lines. Double-click to unfold]
>>> xs *= 3
>>> xs
30: ['Ahoj!',
123,
(12, 'tři'),
['hokus', 'pokus'],
'lokus 666',
'Ahoj!',
123,
(12, 'tři'),
['hokus', 'pokus'],
'lokus 666',
'Ahoj!',
123,
(12, 'tři'),
['hokus', 'pokus'],
'lokus 666']
>>> xs = [1, 2, 3, 4, 5]
>>> xs[3:]
31: [4, 5]
>>> xs[3:] = 666
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
xs[3:] = 666
~~^^^^
TypeError: must assign iterable to extended slice
>>> xs[3:] = [666]
>>> xs
32: [1, 2, 3, 666]
>>> xs.append('a')
>>> xs
33: [1, 2, 3, 666, 'a']
>>> xs.insert(0, '!')
>>> xs
34: ['!', 1, 2, 3, 666, 'a']
>>> xs.extend('b')
>>> xs
35: ['!', 1, 2, 3, 666, 'a', 'b']
>>> xs.extend('cde')
>>> xs
36: ['!', 1, 2, 3, 666, 'a', 'b', 'c', 'd', 'e']
>>> xs += 'FGH'
>>> xs
37: ['!', 1, 2, 3, 666, 'a', 'b', 'c', 'd', 'e', 'F', 'G', 'H']
>>> xs = xs + '321'
Traceback (most recent call last):
File "<pyshell#58>", line 1, in <module>
xs = xs + '321'
~~~^~~~~~~
TypeError: can only concatenate list (not "str") to list
>>> xs = xs + ['321']
>>> xs
38: ['!', 1, 2, 3, 666, 'a', 'b', 'c', 'd', 'e', 'F', 'G', 'H', '321']
>>> xs = xs + ['321', 'abc']
>>> xs
39: ['!', 1, 2, 3, 666, 'a', 'b', 'c', 'd', 'e', 'F', 'G', 'H', '321', '321', 'abc']
>>> names = ["John", "Wendy", "Pete", "Jane", "David", "Amanda", "Ix"]
>>> names
40: ['John', 'Wendy', 'Pete', 'Jane', 'David', 'Amanda', 'Ix']
>>> sorted(names)
41: ['Amanda', 'David', 'Ix', 'Jane', 'John', 'Pete', 'Wendy']
>>> def fn(x):
... print(f'! {x}')
... return x
...
... sorted(names, key=fn)
! John
! Wendy
! Pete
! Jane
! David
! Amanda
! Ix
42: ['Amanda', 'David', 'Ix', 'Jane', 'John', 'Pete', 'Wendy']
>>> def fn(x):
... print(f'! {x}')
... return len(x)
...
... sorted(names, key=fn)
! John
! Wendy
! Pete
! Jane
! David
! Amanda
! Ix
43: ['Ix', 'John', 'Pete', 'Jane', 'Wendy', 'David', 'Amanda']
>>> xs
44: ['!', 1, 2, 3, 666, 'a', 'b', 'c', 'd', 'e', 'F', 'G', 'H', '321', '321', 'abc']
>>> names
45: ['John', 'Wendy', 'Pete', 'Jane', 'David', 'Amanda', 'Ix']
>>> def fn(x):
... print(f'! {x}')
... return len(x), x
...
... sorted(names, key=fn)
! John
! Wendy
! Pete
! Jane
! David
! Amanda
! Ix
46: ['Ix', 'Jane', 'John', 'Pete', 'David', 'Wendy', 'Amanda']
>>> names
47: ['John', 'Wendy', 'Pete', 'Jane', 'David', 'Amanda', 'Ix']
>>> [(len(x), x) for x in names]
48: [(4, 'John'),
(5, 'Wendy'),
(4, 'Pete'),
(4, 'Jane'),
(5, 'David'),
(6, 'Amanda'),
(2, 'Ix')]
>>> sorted(names, key=lambda x: (len(x), x))
49: ['Ix', 'Jane', 'John', 'Pete', 'David', 'Wendy', 'Amanda']
>>> ( (len(x), x) for x in names )
50: <generator object <genexpr> at 0x000001BA2E0DA810>
>>> [x for x in names]
51: ['John', 'Wendy', 'Pete', 'Jane', 'David', 'Amanda', 'Ix']
>>> [len(x) for x in names]
52: [4, 5, 4, 4, 5, 6, 2]
>>> ['!' for x in names]
53: ['!', '!', '!', '!', '!', '!', '!']
>>> ['!' for x in names if len(x) == 4]
54: ['!', '!', '!']
>>> ys = []
... for name in names:
... if len(name) == 4:
... ys.append(name)
>>> ys
55: ['John', 'Pete', 'Jane']
>>> [x for x in names if len(x) == 4]
56: ['John', 'Pete', 'Jane']
>>> [(x,y) for x in range(1, 4) for y in 'abc']
57: [(1, 'a'),
(1, 'b'),
(1, 'c'),
(2, 'a'),
(2, 'b'),
(2, 'c'),
(3, 'a'),
(3, 'b'),
(3, 'c')]
>>> [(x,y)
... for x in range(1, 4)
... for y in 'abc'
... ]
58: [(1, 'a'),
(1, 'b'),
(1, 'c'),
(2, 'a'),
(2, 'b'),
(2, 'c'),
(3, 'a'),
(3, 'b'),
(3, 'c')]
>>> xs = [
... [1, 2, 3],
... [4, 5, 6],
... [7, 8, 9]
... ]
>>> xs[1]
59: [4, 5, 6]
>>> xs[1, -1]
Traceback (most recent call last):
File "<pyshell#86>", line 1, in <module>
xs[1, -1]
~~^^^^^^^
TypeError: list indices must be integers or slices, not tuple
>>> xs[1][-1]
60: 6
>>> xs = '$1,342,321,665'
>>> int(xs)
Traceback (most recent call last):
File "<pyshell#89>", line 1, in <module>
int(xs)
~~~^^^^
ValueError: invalid literal for int() with base 10: '$1,342,321,665'
>>> int(xs[1:])
Traceback (most recent call last):
File "<pyshell#90>", line 1, in <module>
int(xs[1:])
~~~^^^^^^^^
ValueError: invalid literal for int() with base 10: '1,342,321,665'
>>>