Python 3.14.3 (tags/v3.14.3:323c59a, Feb 3 2026, 16:04:56) [MSC v.1944 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
DreamPie 1.2.1
>>> xs = [ ('Láďa', 2), ('Jana', 2), ('Jana', 1), ('Karel', 3) ]
>>> sorted(xs)
0: [('Jana', 1), ('Jana', 2), ('Karel', 3), ('Láďa', 2)]
>>> sorted( [('two', 3), ('one', 4), ('one', 2), ('three', 5), ('two', 1), ] )
1: [('one', 2), ('one', 4), ('three', 5), ('two', 1), ('two', 3)]
>>> sorted( [('two', 3), ('one', 2), ('one', 4), ('three', 5), ('two', 1), ] )
2: [('one', 2), ('one', 4), ('three', 5), ('two', 1), ('two', 3)]
>>> [1, ['a', 'c']] < [1, ['a', 'b'], 3]
3: False
>>> [1, ['a', 'c'], 3] < [1, ['a', 'b'], 3]
4: False
>>> '5' < 6
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
'5' < 6
TypeError: '<' not supported between instances of 'str' and 'int'
>>> names = ["John", "Wendy", "Pete", "Jane", "David", "Amanda", "Ix"]
>>> sorted(names)
5: ['Amanda', 'David', 'Ix', 'Jane', 'John', 'Pete', 'Wendy']
>>> def fn(x):
... print(f'--> {x}')
...
... sorted(names, key=fn)
--> John
--> Wendy
--> Pete
--> Jane
--> David
--> Amanda
--> Ix
Traceback (most recent call last):
File "<pyshell#9>", line 4, in <module>
sorted(names, key=fn)
~~~~~~^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
>>> def fn(x):
... print(f'--> {x}')
... return x
...
... sorted(names, key=fn)
--> John
--> Wendy
--> Pete
--> Jane
--> David
--> Amanda
--> Ix
6: ['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
7: ['Ix', 'John', 'Pete', 'Jane', 'Wendy', 'David', 'Amanda']
>>> names
8: ['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
9: ['Ix', 'Jane', 'John', 'Pete', 'David', 'Wendy', 'Amanda']
>>> def fn(x):
... print(f'--> {x}')
... return len(x), x
...
... sorted(names, key=lambda x: (len(x), x) )
10: ['Ix', 'Jane', 'John', 'Pete', 'David', 'Wendy', 'Amanda']
>>> sorted(['Ahoj!', [1, 2, 3, 'Baf!'], {'já', 'množina', '∞'}, ('xxx', 666)])
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
sorted(['Ahoj!', [1, 2, 3, 'Baf!'], {'já', 'množina', '∞'}, ('xxx', 666)])
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'list' and 'str'
>>> sorted(['Ahoj!', [1, 2, 3, 'Baf!'], {'já', 'množina', '∞'}, ('xxx', 666)], key=len)
11: [('xxx', 666), {'já', '∞', 'množina'}, [1, 2, 3, 'Baf!'], 'Ahoj!']
>>> class Student:
...
... def __init__(self, jméno, známka, věk):
... self.jméno = jméno
... self.známka = známka
... self.věk = věk
...
... def __repr__(self):
... return repr((self.jméno, self.známka, self.věk))
>>> studenti = [
... Student('John', 'A', 15),
... Student('Jane', 'B', 12),
... Student('Dave', 'B', 10),
... ]
>>> studenti
12: [('John', 'A', 15), ('Jane', 'B', 12), ('Dave', 'B', 10)]
>>> type('')
13: <class 'str'>
>>> sorted(studenti)
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
sorted(studenti)
~~~~~~^^^^^^^^^^
TypeError: '<' not supported between instances of 'Student' and 'Student'
>>> class Student:
...
... def __init__(self, jméno, známka, věk):
... self.jméno = jméno
... self.známka = známka
... self.věk = věk
...
... def __repr__(self):
... return repr((self.jméno, self.známka, self.věk))
...
... def __lt__(self, jiný_student):
... return self.věk < jiný_student.věk
>>> studenti
14: [('John', 'A', 15), ('Jane', 'B', 12), ('Dave', 'B', 10)]
>>> sorted(studenti)
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
sorted(studenti)
~~~~~~^^^^^^^^^^
TypeError: '<' not supported between instances of 'Student' and 'Student'
>>> studenti = [
... Student('John', 'A', 15),
... Student('Jane', 'B', 12),
... Student('Dave', 'B', 10),
... ]
>>> sorted(studenti)
15: [('Dave', 'B', 10), ('Jane', 'B', 12), ('John', 'A', 15)]
>>> Student('John', 'A', 15) < Student('Jane', 'B', 12)
16: False
>>> Student('John', 'A', 15).__let__(Student('Jane', 'B', 12))
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
Student('John', 'A', 15).__let__(Student('Jane', 'B', 12))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Student' object has no attribute '__let__'. Did you mean: '__le__'?
>>> Student('John', 'A', 15).__lt__(Student('Jane', 'B', 12))
17: False
>>> xs = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> xs
18: [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> ys = []
... for x in xs:
... ys.append(x*x)
>>> ys
19: [1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> zs = [x*x for x in xs]
>>> zs
20: [1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> x
21: 9
>>> zs = [i**2 for i in xs]
>>> zs
22: [1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> i
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
i
NameError: name 'i' is not defined
>>> zs = [(i, i**2, i**3) for i in xs]
>>> zs
23: [(1, 1, 1),
(2, 4, 8),
(3, 9, 27),
(4, 16, 64),
(5, 25, 125),
(6, 36, 216),
(7, 49, 343),
(8, 64, 512),
(9, 81, 729)]
>>> zs = [(i, i**2, i**3) for i in xs if i % 2 == 1]
>>> zs
24: [(1, 1, 1), (3, 9, 27), (5, 25, 125), (7, 49, 343), (9, 81, 729)]
>>> ys = []
... for x in xs:
... if x % 2 == 1:
... ys.append(x*x)
>>> ys
25: [1, 9, 25, 49, 81]
>>> [x for x in 'ahoj']
26: ['a', 'h', 'o', 'j']
>>> {x for x in 'ahoj'}
27: {'j', 'h', 'o', 'a'}
>>> {x:1 for x in 'ahoj'}
28: {'a': 1, 'h': 1, 'j': 1, 'o': 1}
>>> {x:ord(x) for x in 'ahoj'}
29: {'a': 97, 'h': 104, 'j': 106, 'o': 111}
>>> {x for x in 'příliš žluťoučký kůň úpěl ďábelské ódy'}
30: {' ',
'b',
'd',
'e',
'i',
'k',
'l',
'o',
'p',
's',
'u',
'y',
'á',
'é',
'í',
'ó',
'ú',
'ý',
'č',
'ď',
'ě',
'ň',
'ř',
'š',
'ť',
'ů',
'ž'}
>>> {f'{x}{y}' for x in 'abc' for y in (1, 2, 3)}
31: {'a2', 'b3', 'c1', 'a1', 'b1', 'c2', 'b2', 'a3', 'c3'}
>>> [f'{x}{y}' for x in 'abc' for y in (1, 2, 3)]
32: ['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']
>>> if b'':
... print('Baf!')
>>> if b'abc':
... print('Baf!')
Baf!
>>> if True and True or False:
... print('Baf!')
Baf!
>>> if (True and True) or False:
... print('Baf!')
Baf!
>>> if True or True and False:
... print('Baf!')
Baf!
>>> if True or (True and False):
... print('Baf!')
Baf!
>>> for x in range(1, 6):
... print(x)
... else:
... print('Hotovo!')
1
2
3
4
5
Hotovo!
>>> for x in range(1, 6):
... print(x)
... if x == 3:
... break
... else:
... print('Hotovo!')
1
2
3
>>> range(1, 6)
33: range(1, 6)
>>> list(range(1, 6))
34: [1, 2, 3, 4, 5]
>>> dir(range(1, 6))
35: ['__bool__',
'__class__',
'__contains__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__getstate__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__reversed__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'count',
'index',
'start',
'step',
'stop']
>>> it = iter(range(1, 6))
>>> it
36: <range_iterator object at 0x000002488F0C8290>
>>> dir(it)
37: ['__class__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getstate__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__length_hint__',
'__lt__',
'__ne__',
'__new__',
'__next__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__setstate__',
'__sizeof__',
'__str__',
'__subclasshook__']
>>> next(it)
38: 1
>>> next(it)
39: 2
>>> next(it)
40: 3
>>> next(it)
41: 4
>>> next(it)
42: 5
>>> next(it)
Traceback (most recent call last):
File "<pyshell#72>", line 1, in <module>
next(it)
~~~~^^^^
StopIteration
>>> it = iter(range(1, 6))
>>> next(it)
43: 1
>>> next(it)
44: 2
>>> for i in it:
... print(i)
3
4
5
>>> [(x, o) for x in 'abcdef' if (o := ord(x)) % 2 == 0]
45: [('b', 98), ('d', 100), ('f', 102)]
>>> o
46: 102
>>> x
47: 3
>>> z
Traceback (most recent call last):
File "<pyshell#80>", line 1, in <module>
z
NameError: name 'z' is not defined
>>> p
Traceback (most recent call last):
File "<pyshell#81>", line 1, in <module>
p
NameError: name 'p' is not defined
>>> [(z, p) for z in 'abcdef' if (p := ord(z)) % 2 == 0]
48: [('b', 98), ('d', 100), ('f', 102)]
>>> z
Traceback (most recent call last):
File "<pyshell#83>", line 1, in <module>
z
NameError: name 'z' is not defined
>>> p
49: 102
>>> import math
...
... def vector_length( vector ):
... assert len(vector) == 3
... x,y,z = vector
... return math.sqrt( x**2 + y**2 + z**2 )
>>> vector_length((1, 1, 1))
50: 1.7320508075688772
>>> vector_length((1, 1, 1, 1))
Traceback (most recent call last):
File "<pyshell#87>", line 1, in <module>
vector_length((1, 1, 1, 1))
~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "<pyshell#85>", line 4, in vector_length
assert len(vector) == 3
^^^^^^^^^^^^^^^^
AssertionError
>>> import math
...
... def vector_length( vector ):
... x,y,z = vector
... return math.sqrt( x**2 + y**2 + z**2 )
>>> vector_length((1, 1, 1))
51: 1.7320508075688772
>>> vector_length((1, 1, 1, 1))
Traceback (most recent call last):
File "<pyshell#90>", line 1, in <module>
vector_length((1, 1, 1, 1))
~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "<pyshell#88>", line 4, in vector_length
x,y,z = vector
^^^^^
ValueError: too many values to unpack (expected 3, got 4)
>>> import math
...
... def vector_length( vector ):
... assert len(vector) == 3, 'Wrong dimension!'
... x,y,z = vector
... return math.sqrt( x**2 + y**2 + z**2 )
>>> vector_length((1, 1, 1))
52: 1.7320508075688772
>>> vector_length((1, 1, 1, 1))
Traceback (most recent call last):
File "<pyshell#93>", line 1, in <module>
vector_length((1, 1, 1, 1))
~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "<pyshell#91>", line 4, in vector_length
assert len(vector) == 3, 'Wrong dimension!'
^^^^^^^^^^^^^^^^
AssertionError: Wrong dimension!
>>>