Skip to content

Commit f7dd94b

Browse files
committed
vol1: prep
1 parent 2d0fa5b commit f7dd94b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+15635
-579
lines changed

volumes/1/cap01.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ Como foi implementado até aqui, um `FrenchDeck` não pode ser embaralhado,
325325
porque as cartas e suas posições não podem ser alteradas,
326326
exceto violando o encapsulamento e manipulando o atributo `_cards` diretamente.
327327
No <<ch_ifaces_prot_abc>> vamos corrigir isso acrescentando um método `+__setitem__+`
328-
de uma linha. Você consegue imaginar como ele seria implementado?
328+
de uma linha.
329+
Você consegue imaginar como ele seria implementado?
329330
=====================================================================
330331

331332

volumes/1/cap02.adoc

Lines changed: 199 additions & 171 deletions
Large diffs are not rendered by default.

volumes/1/cap03.adoc

Lines changed: 149 additions & 116 deletions
Large diffs are not rendered by default.

volumes/1/cap04.adoc

Lines changed: 119 additions & 95 deletions
Large diffs are not rendered by default.

volumes/1/cap05.adoc

Lines changed: 119 additions & 107 deletions
Large diffs are not rendered by default.

volumes/1/cap06.adoc

Lines changed: 102 additions & 80 deletions
Large diffs are not rendered by default.

volumes/1/cap07.adoc

Lines changed: 923 additions & 0 deletions
Large diffs are not rendered by default.

volumes/1/cap08.adoc

Lines changed: 2523 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sample code for Chapter 7 - "First-class functions"
2+
3+
From the book "Fluent Python, Second Edition" by Luciano Ramalho (O'Reilly, 2020)
4+
http://shop.oreilly.com/product/0636920273196.do
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
# tag::BINGO_DEMO[]
3+
4+
>>> bingo = BingoCage(range(3))
5+
>>> bingo.pick()
6+
1
7+
>>> bingo()
8+
0
9+
>>> callable(bingo)
10+
True
11+
12+
# end::BINGO_DEMO[]
13+
14+
"""
15+
16+
# tag::BINGO[]
17+
18+
import random
19+
20+
class BingoCage:
21+
22+
def __init__(self, items):
23+
self._items = list(items) # <1>
24+
random.shuffle(self._items) # <2>
25+
26+
def pick(self): # <3>
27+
try:
28+
return self._items.pop()
29+
except IndexError:
30+
raise LookupError('pick from empty BingoCage') # <4>
31+
32+
def __call__(self): # <5>
33+
return self.pick()
34+
35+
# end::BINGO[]

0 commit comments

Comments
 (0)