Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Python: Listas, Dicionarios, Sets e outros mons...
Search
fractal
October 07, 2011
Programming
110
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Python: Listas, Dicionarios, Sets e outros monstros mitológicos
Uma olhada em baixo do capô do python de como as estruturas básicas se comportam
fractal
October 07, 2011
Other Decks in Programming
See All in Programming
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
140
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
220
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.3k
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
590
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
290
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
470
すこし踏み込む CancellationToken
htkym
2
1.6k
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
The Rails Doctrine Decade
koic
2
470
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.6k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
410
Featured
See All Featured
Test your architecture with Archunit
thirion
2
2.4k
Documentation Writing (for coders)
carmenintech
77
5.6k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
720
Agile that works and the tools we love
rasmusluckow
331
22k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
460
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Evolving SEO for Evolving Search Engines
ryanjones
0
310
For a Future-Friendly Web
brad_frost
183
10k
Thoughts on Productivity
jonyablonski
76
5.4k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
Transcript
Listas, Dicionários, Sets e outras Bestas Mitológicas --- Adriano Petrich
O(n)?
Listas
Prós: Fantásticas
Listas l = []
L.append(foo) é O(1)
L.pop() é O(1)
Tá Isso não é tão fantástico
L[foo] = bar, L[foo] O(1)
Isso sim é fantástico
meh
Listas Se comportam como RAM porque são modeladas da mesma
forma
Criação Usa 20 bytes de overhead (classe, len, tamanho da
alocação e posição)
mas Uma lista vazia não tem memória alocada para os
dados.
Quando l.append(1)
Acontece a Alocação Aloca espaço para 4 elementos Quando chega
em 4 aloca espaço para 8 e copia os 4 Depois 16
E assim por diante
Ou Quase 25, 35, 46, 58, 72, 88
L.append(foo) é O(1)
Here be monsters
Cons
L.pop(0) é O(n)
L.pop(0) é O(n)-ish
Alternativa from collections import deque deque()
Deques Double Ended QUEue Internamente é uma lista ligada dupla
Prós Filas FIFO e não muito mais
De volta as listas
foo in L é O(n)
Alternativas set()
Dicionários
Dicionários? >>> d = {} >>> d['a'] = 1
Interlúdio >>> hash('a') 12416037344 >>> bin(hash('a') '0b1011100100000011011011000111100000'
Hashtable
Hash 'a' >>> hash('a') 12416037344 >>> bin(hash('a') '...000'
Hashtable
Hash 'b' >>> d['b'] = 2 >>> hash('b') 12544037731 >>>
bin(hash('b') '...011'
Hashtable
Hash 'c' >>> d['c'] = 3 >>> hash('c') 12672038114 >>>
bin(hash('c') '...010'
Hashtable
None
Hash 'j' >>> d['j'] = 4 >>> hash('j') 13568040811 >>>
bin(hash('j') '...011'
Enquanto isso na Hashtable
Outra vez na Hashtable
Duas coisas >>> d1 = {'a':1, 'j':4, 'b':2} >>> d2
= {'a':1, 'b':2, 'j':4} >>> d1 {'a': 1, 'j': 4, 'b': 2} >>> d2 {'a': 1, 'b': 2, 'j': 4} >>> d1 == d2 True
Dicionários não tem ordem Tem sim! A ordem da hashtable
>>> {'a':1, 'j':4, 'b':2}.keys() ['a', 'j', 'b'] >>> {'a':1, 'j':4, 'b':2}.values() [1, 4, 2]
Existem bem mais sutilezas Vídeo da pycon 2010: the might
dictionary
Sets
Sets Implementação igual dos dicionários só que sem o valor.
Então:
foo in s é O(1)
Grafos
A B C D
A B C D
Duas formas a,b,c,d = range(4) n = [[0,1,1,0], [0,0,1,0], [0,0,0,1],
[0,0,0,0]] >>> n[a][b] 1
Ou n = { 'a': set('bc'), 'b': set('c'), 'c': set('d'),
'd': set()} Python Patterns implementing graphs --Guido van Rossum
A B C D 2 3 4 5
passe para dicionários n = { 'a': {'b':2, 'c':3}, 'b':
{'c':4}, 'c': {'d':5}, 'd': {}}
Créditos http://www.flickr.com/photos/autumn_bliss/414160195 http://www.flickr.com/photos/autumn_bliss/414160148
Dúvidas? @fractal +Adriano Petrich [codando.com.br, sfp.adrianopetrich.com, blog.adrianopetrich.com]