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
>>> for i in range(10):
... print(i, end=' ')
... else:
... print('Konec!')
0 1 2 3 4 5 6 7 8 9 Konec!
>>> for i in range(10):
... if i == 7: break
... print(i, end=' ')
... else:
... print('Konec!')
0 1 2 3 4 5 6
>>> i
0: 7
>>> for i in range(10):
... if i == 7: break
... print(i, end=' ')
... else:
... print('Konec!')
... del i
0 1 2 3 4 5 6
>>> i
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
i
NameError: name 'i' is not defined
>>> 'ahoj'*3
1: 'ahojahojahoj'
>>> 3*'ahoj'
2: 'ahojahojahoj'
>>> 'ahoj'*0
3: ''
>>> sorted('koníček')
4: ['e', 'k', 'k', 'n', 'o', 'í', 'č']
>>> import locale
>>> sorted('koníček', key=locale.strxfrm)
5: ['e', 'k', 'k', 'n', 'o', 'í', 'č']
>>> locale.setlocale(locale.LC_ALL, 'czech')
6: 'Czech_Czechia.1250'
>>> sorted('koníček', key=locale.strxfrm)
7: ['č', 'e', 'í', 'k', 'k', 'n', 'o']
>>> hash(1)
8: 1
>>> hash('ahoj')
9: -7929849846895080554
>>> hash(('ahoj', 1))
10: 431564283804132431
>>> hash(print)
11: -4611677369817192512
>>> hash([1, 'ahoj'])
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
hash([1, 'ahoj'])
TypeError: unhashable type: 'list'
>>> eval('2+3')
12: 5
>>> eval('for x in "ahoj": print(x)')
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
eval('for x in "ahoj": print(x)')
File "<string>", line 1
for x in "ahoj": print(x)
^^^
SyntaxError: invalid syntax
>>> eval('import os')
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
eval('import os')
File "<string>", line 1
import os
^^^^^^
SyntaxError: invalid syntax
>>> for i in range(5): print(i)
0
1
2
3
4
>>> for i in range(5): print(i); print('Baf!')
0
Baf!
1
Baf!
2
Baf!
3
Baf!
4
Baf!
>>> len('ahoj')
13: 4
>>> '12 to by nešlo 24'.strip('123')
14: ' to by nešlo 24'
>>> '12 to by nešlo 24'.strip('1234')
15: ' to by nešlo '
>>> '12 to by nešlo 24'.strip('134')
16: '2 to by nešlo 2'
>>> '12 to by nešlo 24'.strip()
17: '12 to by nešlo 24'
>>> ' \t \n 12 to by nešlo 24 '.strip()
18: '12 to by nešlo 24'
>>> len('Harry Potter and the Deathly Hallows – Part 2')
19: 45
>>> xs = [
... ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
... ['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
... ['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
... ['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
... ['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
... ['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
... ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
... ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
... ]
>>> len(xs)
20: 8
>>> xs[-1]
21: ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']
>>> sorted(xs)
22: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']]
>>> sorted(xs, key=lambda x: x[1])
23: [['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']]
>>> def řazení(x):
... print(x)
... return x
>>> sorted(xs, key=řazení)
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus']
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus']
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell']
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates']
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates']
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates']
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']
24: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']]
>>> def řazení(x):
... print('-->', x)
... return x
>>> sorted(xs, key=řazení)
--> ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus']
--> ['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus']
--> ['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']
--> ['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell']
--> ['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates']
--> ['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates']
--> ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates']
--> ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']
25: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']]
>>> def řazení(x):
... print('-->', x)
... return x[1]
>>> sorted(xs, key=řazení)
--> ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus']
--> ['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus']
--> ['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']
--> ['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell']
--> ['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates']
--> ['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates']
--> ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates']
--> ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']
26: [['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']]
>>> def řazení(x):
... print('-->', x)
... return x[-1]
>>> sorted(xs, key=řazení)
--> ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus']
--> ['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus']
--> ['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']
--> ['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell']
--> ['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates']
--> ['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates']
--> ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates']
--> ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates']
27: [['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell']]
>>> sorted(xs, key=lambda x: (x[1], -x[-2]))
Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
sorted(xs, key=lambda x: (x[1], -x[-2]))
File "<pyshell#43>", line 1, in <lambda>
sorted(xs, key=lambda x: (x[1], -x[-2]))
TypeError: bad operand type for unary -: 'str'
>>> sorted(xs, key=lambda x: (x[1], x[-2]))
28: [['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']]
>>> sorted(xs, key=lambda x: (x[1], x[-2]), reverse=True)
29: [['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus']]
>>> sorted(xs, key=lambda x: (x[1], x[-2]))
30: [['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón']]
>>> sorted(xs, key=lambda x: (x[-1], x[-2]))
31: [['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell']]
>>> sorted(xs, key=lambda x: (x[-1], -int(x[-2])))
32: [['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'],
['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'],
['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'],
['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'],
['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'],
['6', 'Harry Potter and the Half-Blood Prince', '2009', 'David Yates'],
['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'],
['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell']]
>>> unicodedata.normalize('NFD', 'koníček').encode('ascii', 'ignore').decode('ascii')
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
unicodedata.normalize('NFD', 'koníček').encode('ascii', 'ignore').decode('ascii')
NameError: name 'unicodedata' is not defined
>>> import unicodedata
>>> unicodedata.normalize('NFD', 'koníček').encode('ascii', 'ignore').decode('ascii')
33: 'konicek'
>>> unicodedata.normalize('NFD', 'koníček').encode('ascii', 'ignore')
34: b'konicek'
>>> unicodedata.normalize('NFD', 'koníček')
35: 'koníček'
>>> 'koníček'.encode('ascii', 'ignore')
36: b'konek'
>>> 'koníček'.encode('ascii')
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
'koníček'.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-4: ordinal not in range(128)
>>> xs = 'text nezáživný obsahující slov vybraných několik'
>>> xs.split()
37: ['text', 'nezáživný', 'obsahující', 'slov', 'vybraných', 'několik']
>>> xs = 'text nezáživný obsahující slov vybraných několik'.split()
>>> xs
38: ['text', 'nezáživný', 'obsahující', 'slov', 'vybraných', 'několik']
>>> sorted(xs)
39: ['nezáživný', 'několik', 'obsahující', 'slov', 'text', 'vybraných']
>>> sorted(xs, key=lambda x: (..., len(x), x))
40: ['slov', 'text', 'několik', 'nezáživný', 'vybraných', 'obsahující']
>>> sorted(xs, key=lambda x: (..., len(x)))
41: ['text', 'slov', 'několik', 'nezáživný', 'vybraných', 'obsahující']
>>> sorted(xs, key=lambda x: (..., len(x), x))
42: ['slov', 'text', 'několik', 'nezáživný', 'vybraných', 'obsahující']
>>> def samohlásek(x):
... x = x.lower()
... i = 0
... for x in 'aeiouy':
... i += x.count(x)
... return i
>>> sorted(xs, key=lambda x: (samohlásek(x), len(x), x))
43: ['slov', 'text', 'několik', 'nezáživný', 'vybraných', 'obsahující']
>>> def samohlásek(x):
... x = x.lower()
... i = 0
... for x in 'aáeéěiíoóuůúyý':
... i += x.count(x)
... return i
>>> sorted(xs, key=lambda x: (samohlásek(x), len(x), x))
44: ['slov', 'text', 'několik', 'nezáživný', 'vybraných', 'obsahující']
>>> def samohlásek(x):
... x = x.lower()
... i = 0
... for z in 'aáeéěiíoóuůúyý':
... i += x.count(z)
... return i
>>> sorted(xs, key=lambda x: (samohlásek(x), len(x), x))
45: ['slov', 'text', 'několik', 'vybraných', 'nezáživný', 'obsahující']
>>> def samohlásek(x):
... x, i = x.lower(), 0
... for samohláska in 'aáeéěiíoóuůúyý':
... i += x.count(samohláska)
... return i
>>> sorted(xs, key=lambda x: (samohlásek(x), len(x), x))
46: ['slov', 'text', 'několik', 'vybraných', 'nezáživný', 'obsahující']
>>> xs
47: ['text', 'nezáživný', 'obsahující', 'slov', 'vybraných', 'několik']
>>>