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 >>> xs = "1;Harry Potter and the Philosopher's Stone;2001;Chris Columbus" >>> ys = '1;Harry Potter and the Philosopher\'s Stone;2001;Chris Columbus' >>> xs == ys 0: True >>> xs 1: "1;Harry Potter and the Philosopher's Stone;2001;Chris Columbus" >>> ys 2: "1;Harry Potter and the Philosopher's Stone;2001;Chris Columbus" >>> xs.replace(';', '\t') 3: "1\tHarry Potter and the Philosopher's Stone\t2001\tChris Columbus" >>> print(xs.replace(';', '\t')) 1 Harry Potter and the Philosopher's Stone 2001 Chris Columbus >>> print(xs.replace(';', '\t', 2)) 1 Harry Potter and the Philosopher's Stone 2001;Chris Columbus >>> print(xs.replace(';', '\t', 1)) 1 Harry Potter and the Philosopher's Stone;2001;Chris Columbus >>> xs.split() 4: ['1;Harry', 'Potter', 'and', 'the', "Philosopher's", 'Stone;2001;Chris', 'Columbus'] >>> xs.split() == xs.split(' ') 5: True >>> xs.split(' ') 6: ['1;Harry', 'Potter', 'and', 'the', "Philosopher's", 'Stone;2001;Chris', 'Columbus'] >>> xs.split(';') 7: ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'] >>> xs 8: "1;Harry Potter and the Philosopher's Stone;2001;Chris Columbus" >>> '|'.join( xs.split(';') ) 9: "1|Harry Potter and the Philosopher's Stone|2001|Chris Columbus" >>> '|'.join( ... ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'] ... ) 10: "1|Harry Potter and the Philosopher's Stone|2001|Chris Columbus" >>> '+|+'.join( ... ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'] ... ) 11: "1+|+Harry Potter and the Philosopher's Stone+|+2001+|+Chris Columbus" >>> xs.replace(';', '+|+') 12: "1+|+Harry Potter and the Philosopher's Stone+|+2001+|+Chris Columbus" >>> '+|+'.join( ... ('1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus') ... ) 13: "1+|+Harry Potter and the Philosopher's Stone+|+2001+|+Chris Columbus" >>> '+|+'.join( ... '1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus' ... ) Traceback (most recent call last): File "<pyshell#19>", line 1, in <module> '+|+'.join( TypeError: str.join() takes exactly one argument (4 given) >>> '+|+'.join( ... "Harry Potter and the Philosopher's Stone" ... ) 14: ('H+|+a+|+r+|+r+|+y+|+ +|+P+|+o+|+t+|+t+|+e+|+r+|+ +|+a+|+n+|+d+|+ ' "+|+t+|+h+|+e+|+ +|+P+|+h+|+i+|+l+|+o+|+s+|+o+|+p+|+h+|+e+|+r+|+'+|+s+|+ " '+|+S+|+t+|+o+|+n+|+e') >>> xs.split(';') 15: ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'] >>> xs.split(';', 1) 16: ['1', "Harry Potter and the Philosopher's Stone;2001;Chris Columbus"] >>> xs.rsplit(';', 1) 17: ["1;Harry Potter and the Philosopher's Stone;2001", 'Chris Columbus'] >>> len(xs.rsplit(';', 1)) 18: 2 >>> a, b = xs.rsplit(';', 1) >>> a 19: "1;Harry Potter and the Philosopher's Stone;2001" >>> b 20: 'Chris Columbus' >>> _, b = xs.rsplit(';', 1) >>> b 21: 'Chris Columbus' >>> _ 22: 'Chris Columbus' >>> _2 23: "1;Harry Potter and the Philosopher's Stone;2001;Chris Columbus" >>> __ 24: 'Chris Columbus' >>> xs 25: "1;Harry Potter and the Philosopher's Stone;2001;Chris Columbus" >>> xs = " Hello World, I am here. " >>> xs 26: ' Hello World, I am here. ' >>> xs.split() 27: ['Hello', 'World,', 'I', 'am', 'here.'] >>> ' '.join(['Hello', 'World,', 'I', 'am', 'here.']) 28: 'Hello World, I am here.' >>> xs = " Hello World, \n\t I am here. " >>> xs 29: ' Hello World, \n\t I am here. ' >>> print(xs) Hello World, I am here. >>> xs.split() 30: ['Hello', 'World,', 'I', 'am', 'here.'] >>> xs = """Tady je velmi dlouhý text, ... který zabírá více řádek. Aby také ... ... ... nezabíral, když je v něm napsáno tolik ... nesmyslů, že. ... """ >>> xs.splitlines() 31: ['Tady je velmi dlouhý text,', 'který zabírá více řádek. Aby také ', '', '', 'nezabíral, když je v něm napsáno tolik', 'nesmyslů, že.'] >>> xs.split('\n') 32: ['Tady je velmi dlouhý text,', 'který zabírá více řádek. Aby také ', '', '', 'nezabíral, když je v něm napsáno tolik', 'nesmyslů, že.', ''] >>> ys 33: "1;Harry Potter and the Philosopher's Stone;2001;Chris Columbus" >>> xs = 'abeceda' >>> for x in xs: ... print(x) a b e c e d a >>> it = iter(xs) >>> for x in it: ... print(x) a b e c e d a >>> it = iter(xs) >>> next(it) 34: 'a' >>> next(it) 35: 'b' >>> next(it) 36: 'e' >>> next(it) 37: 'c' >>> for x in it: ... print(x) e d a >>> len('Harry Potter and the Deathly Hallows – Part 1') 38: 45 >>> xs = ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'] >>> xs 39: ['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'] >>> type(xs) 40: <class 'list'> >>> xs[1] 41: "Harry Potter and the Philosopher's Stone" >>> xs[0] 42: '1' >>> a, b, c, d = xs >>> a 43: '1' >>> b 44: "Harry Potter and the Philosopher's Stone" >>> c 45: '2001' >>> d 46: 'Chris Columbus' >>> b.ljust(45) 47: "Harry Potter and the Philosopher's Stone " >>> b.rjust(45) 48: " Harry Potter and the Philosopher's Stone" >>> b.center(45) 49: " Harry Potter and the Philosopher's Stone " >>> print(f'{b:<45}') Harry Potter and the Philosopher's Stone >>> print(f'|{b:<45}|') |Harry Potter and the Philosopher's Stone | >>> print(f'|{b: <45}|') |Harry Potter and the Philosopher's Stone | >>> filmy = [['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(filmy) 50: 8 >>> filmy[1] 51: ['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'] >>> filmy[1:] 52: [['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']] >>> filmy[:1] 53: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus']] >>> filmy[:2] 54: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'], ['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus']] >>> filmy[::2] 55: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'], ['3', 'Harry Potter and the Prisoner of Azkaban', '2004', 'Alfonso Cuarón'], ['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates'], ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates']] >>> filmy[::3] 56: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'], ['4', 'Harry Potter and the Goblet of Fire', '2005', 'Mike Newell'], ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates']] >>> filmy[::4] 57: [['1', "Harry Potter and the Philosopher's Stone", '2001', 'Chris Columbus'], ['5', 'Harry Potter and the Order of the Phoenix', '2007', 'David Yates']] >>> filmy[-1] 58: ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', 'David Yates'] >>> sorted(filmy) 59: [['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(['1', '2', '11']) 60: ['1', '11', '2'] >>> reversed(filmy) 61: <list_reverseiterator object at 0x0000028517F90910> >>> for film in reversed(filmy): ... print(film) ['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'] ['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'] >>> sorted(['1', '2', '11'], key=lambda x: int(x)) 62: ['1', '2', '11'] >>> sorted(['1', '12', '3', '11', '2']) 63: ['1', '11', '12', '2', '3'] >>> sorted(['1', '12', '3', '11', '2'], key=lambda x: int(x)) 64: ['1', '2', '3', '11', '12'] >>> def fn(x): ... print('-->', x) ... return int(x) >>> sorted(['1', '12', '3', '11', '2'], key=fn) --> 1 --> 12 --> 3 --> 11 --> 2 65: ['1', '2', '3', '11', '12'] >>> '111' < '2' 66: True >>> '211' < '2' 67: False >>> int('12') 68: 12 >>> int('111') < int('2') 69: False >>> filmy 70: [['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 fn(x): ... print('-->', x) ... return x >>> sorted(filmy, key=fn) --> ['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'] 71: [['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 fn(x): ... print('-->', x) ... return x[1] >>> sorted(filmy, key=fn) --> ['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'] 72: [['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 fn(x): ... print('-->', x) ... return x[3] >>> sorted(filmy, key=fn) --> ['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'] 73: [['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']] >>> def fn(x): ... return x[-1] >>> sorted(filmy, key=fn) 74: [['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']] >>> 'Alfonso Cuarón'.split() 75: ['Alfonso', 'Cuarón'] >>> 'Alfonso Cuarón'.split()[-1] 76: 'Cuarón' >>> def fn(x): ... return x[-1].split()[-1] >>> sorted(filmy, key=fn) 77: [['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 fn(x): ... return x[-1].split()[-1], x[1] >>> sorted(filmy, key=fn) 78: [['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'], ['1', "Harry Potter and the Philosopher's Stone", '2001', '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'], ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'], ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', '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']] >>> sorted(filmy, key=lambda x: (x[-1].split()[-1], x[1])) 79: [['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus'], ['1', "Harry Potter and the Philosopher's Stone", '2001', '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'], ['7a', 'Harry Potter and the Deathly Hallows – Part 1', '2010', 'David Yates'], ['7b', 'Harry Potter and the Deathly Hallows – Part 2', '2011', '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']] >>> sorted(filmy, key=lambda x: x[1]) 80: [['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']] >>> ';'.join(['2', 'Harry Potter and the Chamber of Secrets', '2002', 'Chris Columbus']) 81: '2;Harry Potter and the Chamber of Secrets;2002;Chris Columbus' >>>