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 >>> tržby = '$1,342,321,665' >>> tržby > 1000000000 Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> tržby > 1000000000 TypeError: '>' not supported between instances of 'str' and 'int' >>> tržby > 1_000_000_000 Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> tržby > 1_000_000_000 TypeError: '>' not supported between instances of 'str' and 'int' >>> int(tržby) Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> int(tržby) ~~~^^^^^^^ ValueError: invalid literal for int() with base 10: '$1,342,321,665' >>> int('123') > 100 0: True >>> int('123') 1: 123 >>> int('1.23') Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> int('1.23') ~~~^^^^^^^^ ValueError: invalid literal for int() with base 10: '1.23' >>> float('1.23') 2: 1.23 >>> tržby 3: '$1,342,321,665' >>> tržby[1:] 4: '1,342,321,665' >>> tržby[0] 5: '$' >>> int(tržby[1:]) Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> int(tržby[1:]) ~~~^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: '1,342,321,665' >>> tržby[1:].replace(',', '') 6: '1342321665' >>> int( tržby[1:].replace(',', '') ) 7: 1342321665 >>> int( tržby[1:].replace(',', '') ) > 1_000_000_000 8: True >>> tržby 9: '$1,342,321,665' >>> tržby.strip('$') 10: '1,342,321,665' >>> tržby.lstrip('$') 11: '1,342,321,665' >>> tržby.lstrip('$').split(',') 12: ['1', '342', '321', '665'] >>> ''.join( tržby.lstrip('$').split(',') ) 13: '1342321665' >>> '-'.join( tržby.lstrip('$').split(',') ) 14: '1-342-321-665' >>> for prvek in tržby.lstrip('$').split(','): ... print(prvek) 1 342 321 665 >>> ''.join( tržby[1:].split(',') ) 15: '1342321665' >>> xs = tržby[1:].split(',') >>> xs 16: ['1', '342', '321', '665'] >>> ''.join(xs) 17: '1342321665' >>> for prvek in xs: ... print(prvek) 1 342 321 665 >>> i = 0 ... for prvek in xs: ... i += 1 >>> i 18: 4 >>> i = 0 ... for prvek in xs: ... i = i + 1 >>> i 19: 4 >>> i = 0 ... for prvek in xs: ... i = i + 1 ... print(i, prvek) 1 1 2 342 3 321 4 665 >>> for i,prvek in enumerate(xs, start=1): ... print(prvek) 1 342 321 665 >>> i 20: 4 >>> for i,prvek in enumerate(xs, start=1): ... print(i, prvek) 1 1 2 342 3 321 4 665 >>> i 21: 4 >>> prvek 22: '665' >>> for i,prvek in enumerate(xs, start=10): ... print(i, prvek) 10 1 11 342 12 321 13 665 >>> i 23: 13 >>> xs 24: ['1', '342', '321', '665'] >>> len(xs) 25: 4 >>> xs[0] 26: '1' >>> xs[-1] 27: '665' >>> xs[3] 28: '665' >>> xs[len(xs) - 1] 29: '665' >>> xs.append(666) >>> xs 30: ['1', '342', '321', '665', 666] >>> xs = [] >>> xs 31: [] >>> xs.append(666) >>> xs 32: [666] >>> xs.append(333) >>> xs 33: [666, 333] >>> xs.append(666) >>> xs 34: [666, 333, 666] >>> xs.append(666) >>> xs 35: [666, 333, 666, 666] >>> sum(xs) 36: 2331 >>> 666 + 333 + 666 + 666 37: 2331 >>> xs 38: [666, 333, 666, 666] >>> xs.append('a', 'b') Traceback (most recent call last): File "<pyshell#60>", line 1, in <module> xs.append('a', 'b') ~~~~~~~~~^^^^^^^^^^ TypeError: list.append() takes exactly one argument (2 given) >>> xs.append( ('a', 'b') ) >>> xs 39: [666, 333, 666, 666, ('a', 'b')] >>> xs[-1] 40: ('a', 'b') >>> 'a', 'b' 41: ('a', 'b') >>> xs = ['c', 'a', 'b', 'e', 'd'] >>> xs 42: ['c', 'a', 'b', 'e', 'd'] >>> for znak in xs: ... print(znak) c a b e d >>> for znak in sorted(xs): ... print(znak) a b c d e >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ... ('Deathly Hallows – Part 1', '2010', 'David Yates', '$977,043,483'), ... ('Deathly Hallows – Part 2', '2011', 'David Yates', '$1,342,321,665'), ... ] >>> filmy 43: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ('Deathly Hallows – Part 1', '2010', 'David Yates', '$977,043,483'), ('Deathly Hallows – Part 2', '2011', 'David Yates', '$1,342,321,665')] >>> sorted(filmy) 44: [('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Deathly Hallows – Part 1', '2010', 'David Yates', '$977,043,483'), ('Deathly Hallows – Part 2', '2011', 'David Yates', '$1,342,321,665'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ... ('Deathly Hallows', '2010', 'David Yates', '$977,043,483'), ... ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ... ] >>> filmy 45: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ('Deathly Hallows', '2010', 'David Yates', '$977,043,483'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665')] >>> sorted(filmy) 46: [('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Deathly Hallows', '2010', 'David Yates', '$977,043,483'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ... ('Deathly Hallows', '2012', 'David Yates', '$977,043,483'), ... ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ... ] >>> filmy 47: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ('Deathly Hallows', '2012', 'David Yates', '$977,043,483'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665')] >>> sorted(filmy) 48: [('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ('Deathly Hallows', '2012', 'David Yates', '$977,043,483'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Half-Blood Prince', '2009', 'David Yates', '$934,454,096'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618')] >>> zs = ('1', "Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171') >>> len(zs) 49: 5 >>> type(zs) 50: <class 'tuple'> >>> zs[1:] 51: ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171') >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$124,454,096'), ... ('Deathly Hallows', '2012', 'David Yates', '$977,043,483'), ... ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ... ] >>> sorted() Traceback (most recent call last): File "<pyshell#83>", line 1, in <module> sorted() ~~~~~~^^ TypeError: sorted expected 1 argument, got 0 >>> sorted(filmy) 52: [('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ('Deathly Hallows', '2012', 'David Yates', '$977,043,483'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Half-Blood Prince', '2009', 'David Yates', '$124,454,096'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618')] >>> sorted(filmy, key=lambda prvek: prvek[-1]) 53: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ('Half-Blood Prince', '2009', 'David Yates', '$124,454,096'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ('Deathly Hallows', '2012', 'David Yates', '$977,043,483')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$1,240,454,096'), ... ('Deathly Hallows', '2012', 'David Yates', '$977,043,483'), ... ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ... ] >>> sorted(filmy, key=lambda prvek: prvek[-1]) 54: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Half-Blood Prince', '2009', 'David Yates', '$1,240,454,096'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$879,602,366'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ('Deathly Hallows', '2012', 'David Yates', '$977,043,483')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$9,879,602,366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$1,240,454,096'), ... ('Deathly Hallows', '2012', 'David Yates', '$977,043,483'), ... ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ... ] >>> sorted(filmy, key=lambda prvek: prvek[-1]) 55: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171'), ('Half-Blood Prince', '2009', 'David Yates', '$1,240,454,096'), ('Deathly Hallows', '2011', 'David Yates', '$1,342,321,665'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797,361,618'), ('Goblet of Fire', '2005', 'Mike Newell', '$896,678,241'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$9,879,602,366'), ('Order of the Phoenix', '2007', 'David Yates', '$942,172,396'), ('Deathly Hallows', '2012', 'David Yates', '$977,043,483')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1006968171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896678241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$942172396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$1240454096'), ... ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ... ('Deathly Hallows', '2011', 'David Yates', '$1342321665'), ... ] >>> sorted(filmy, key=lambda prvek: prvek[-1]) 56: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1006968171'), ('Half-Blood Prince', '2009', 'David Yates', '$1240454096'), ('Deathly Hallows', '2011', 'David Yates', '$1342321665'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ('Goblet of Fire', '2005', 'Mike Newell', '$896678241'), ('Order of the Phoenix', '2007', 'David Yates', '$942172396'), ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$1006968171'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896678241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$992172396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$1240454096'), ... ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ... ('Deathly Hallows', '2011', 'David Yates', '$1342321665'), ... ] >>> sorted(filmy, key=lambda prvek: prvek[-1]) 57: [("Philosopher's Stone", '2001', 'Chris Columbus', '$1006968171'), ('Half-Blood Prince', '2009', 'David Yates', '$1240454096'), ('Deathly Hallows', '2011', 'David Yates', '$1342321665'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ('Goblet of Fire', '2005', 'Mike Newell', '$896678241'), ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366'), ('Order of the Phoenix', '2007', 'David Yates', '$992172396')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$100696817'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$896678241'), ... ('Order of the Phoenix', '2007', 'David Yates', '$992172396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$124045409'), ... ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ... ('Deathly Hallows', '2011', 'David Yates', '$134232166'), ... ] >>> sorted(filmy, key=lambda prvek: prvek[-1]) 58: [("Philosopher's Stone", '2001', 'Chris Columbus', '$100696817'), ('Half-Blood Prince', '2009', 'David Yates', '$124045409'), ('Deathly Hallows', '2011', 'David Yates', '$134232166'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ('Goblet of Fire', '2005', 'Mike Newell', '$896678241'), ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366'), ('Order of the Phoenix', '2007', 'David Yates', '$992172396')] >>> filmy = [ ... ("Philosopher's Stone", '2001', 'Chris Columbus', '$100696817'), ... ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366'), ... ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ... ('Goblet of Fire', '2005', 'Mike Newell', '$8'), ... ('Order of the Phoenix', '2007', 'David Yates', '$992172396'), ... ('Half-Blood Prince', '2009', 'David Yates', '$124045409'), ... ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ... ('Deathly Hallows', '2011', 'David Yates', '$134232166'), ... ] >>> sorted(filmy, key=lambda prvek: prvek[-1]) 59: [("Philosopher's Stone", '2001', 'Chris Columbus', '$100696817'), ('Half-Blood Prince', '2009', 'David Yates', '$124045409'), ('Deathly Hallows', '2011', 'David Yates', '$134232166'), ('Prisoner of Azkaban', '2004', 'Alfonso Cuarón', '$797361618'), ('Goblet of Fire', '2005', 'Mike Newell', '$8'), ('Deathly Hallows', '2012', 'David Yates', '$977043483'), ('Chamber of Secrets', '2002', 'Chris Columbus', '$9879602366'), ('Order of the Phoenix', '2007', 'David Yates', '$992172396')] >>> xs 60: ['c', 'a', 'b', 'e', 'd'] >>> ys Traceback (most recent call last): File "<pyshell#99>", line 1, in <module> ys NameError: name 'ys' is not defined >>> zs 61: ('1', "Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171') >>> zs[-1] 62: '$1,006,968,171' >>> zs[4:] 63: ('$1,006,968,171',) >>> zs[1:] 64: ("Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171') >>> zs 65: ('1', "Philosopher's Stone", '2001', 'Chris Columbus', '$1,006,968,171') >>> type(zs) 66: <class 'tuple'> >>> from collections import namedtuple >>> Film = namedtuple('FilmInfo', 'pořadí, název, rok, režizér, tržby') >>> film = Film(zs) Traceback (most recent call last): File "<pyshell#108>", line 1, in <module> film = Film(zs) TypeError: FilmInfo.__new__() missing 4 required positional arguments: 'název', 'rok', 'režizér', and 'tržby' >>> film = Film(*zs) >>> film 67: FilmInfo(pořadí='1', název="Philosopher's Stone", rok='2001', režizér='Chris Columbus', tržby='$1,006,968,171') >>> film[-1] 68: '$1,006,968,171' >>> film.tržby 69: '$1,006,968,171' >>> film.název 70: "Philosopher's Stone" >>> film[1] 71: "Philosopher's Stone" >>> int('3') 72: 3 >>> int(' 3') 73: 3 >>>