Jordi Riera
● Software developer @ Rodeo FX
● Founder @ cgstudiomap.org
● 8 ans à écrire du python
● kender.jr@gmail.com
● @jordiriera_cg
● https://www.linkedin.com/in/jordirieracg/
● https://github.com/foutoucour/
How To Train Your Python
Les bases sur les iterables
Iterables
+ de 10 types d’iterables
liste, et pas que
● List & deque
● Tuple & namedtuple
● String
● Set & frozenset
● Dict, Ordereddict, ChainMap, Counter & defaultdict
● Generators
● Range, zip, map, file object, et autres.
Lequel choisir?
Lequel choisir?
● List, deque, tuple, string, generators, Ordereddict: ordonnés
● Tuple, frozenset: immuables (well... kind of... :( )
● Set & frozenset: caractère unique
● Dict, Ordereddict, ChainMap, Counter & defaultdict: mapping
● String: ... ben... string quoi...
● Generators, range, zip, map, etc: optimisation, consommation
for loop
languages = [‘php’, ‘ruby’, ‘python’]
frameworks = [‘symfony’, ‘ruby on rails’, ‘django’]
for i in range(len(languages)):
print(languages[i] + ‘: ’ + frameworks[i])
for loop
languages = [‘php’, ‘ruby’, ‘python’]
frameworks = [‘symfony’, ‘ruby on rails’, ‘django’]
for i, language in enumerate(languages):
print(‘: ’.join([language, frameworks[i]]))
for language, framework in zip(languages, frameworks):
print(‘: ’.join([language, framework]))
Set
random_numbers = [ 3, 4, 4, 1, 2, 3, 1]
set(random_numbers)
>>> {1, 2, 3, 4}
frozenset(random_numbers)
>>> frozenset({1, 2, 3, 4})
Set
Sets acceptent les
opérations mathématiques:
● Union
● Intersection
● Difference
● Et d’autres opérations
plus chelou, mais ça fait
de jolies figures
dict, feel the powa!
mapping = dict() # ou {}
for language, framework in zip(languages, frameworks):
if not language in languages:
mapping[language] = []
mapping[language].append(framework)
dict
mapping = defaultdict(list)
for language, framework in zip(languages, frameworks):
mapping[language].append(framework)
mapping = {}
for l, framework in zip(languages, frameworks):
mapping.setdefault(l, []).append(framework)
dict
dict
mapping = {‘php’:[‘symfony’], ‘ruby’:[’ruby on rails’],
‘python’:[’django’]}
for language in mapping:
print(language)
for language, frameworks in mapping.items():
print(language, frameworks)
dict
mapping = {‘php’:[‘symfony’], ‘ruby’:[’ruby on rails’],
‘python’:[’django’]}
print(mapping[‘python’])
del mapping[‘python’]
print(mapping.get(‘python’, ‘flask’))
Mapping[‘python’] = ‘pyramid’
muabilité
# Les listes sont muables. Elles peuvent être mis à jour:
list1 = [1,]
list1.append(2)
list1 == [1, 2]
Et d’autres méthodes...
list2 = [1,]
list2.insert(0, 2)
list2 == [2, 1]
muabilité
# Cool mais...
list2 = list1
list1.append(3)
list2 == [1, 2, 3]
# list2 “pointe” vers list1.
# list1 et list2 sont la même
liste en fait...
muabilité
# Solution
list2 = list1[:]
# list2 est une liste avec
tous les éléments de list1
# you’re welcome ;)
# Les tuples sont immuables,
# ils ne peuvent pas être mis à jour:
tuple1 = (1,)
tuple1.append(2)
Raise AttributeError
immuabilité
# enfin...
list1 = [1,]
tuple1 = (1, list1)
list1.append(2)
tuple1 == (1, [1, 2])
# pas cool bro!
immuabilité
Compréhension à la portée de tous!
list1 = [x for x in z if not x == ‘foo’]
gen = (x for x in z if not x == ‘foo’)
# Nope c’est pas un tuple! Mais un générateur.
set1 = {x for x in z if not x == ‘foo’}
dic1 = {x: x.bar for x in z if not x == ‘foo’}
Questions?
● kender.jr@gmail.com
● @jordiriera_cg
● https://www.linkedin.com/in/jordirieracg/
● https://github.com/foutoucour/

More Related Content

PDF
Memory Debugging
PDF
Learning groovy -EU workshop
PDF
Why go ?
ZIP
拡張ライブラリをD言語で作るとリア充
PPT
Sphinx как база данных
PDF
How To Train Your Python
PDF
Intro to Python
Memory Debugging
Learning groovy -EU workshop
Why go ?
拡張ライブラリをD言語で作るとリア充
Sphinx как база данных
How To Train Your Python
Intro to Python

Similar to How to train your python: iterables (FR) (20)

PDF
A Few of My Favorite (Python) Things
PDF
Python Usage (5-minute-summary)
PDF
Python-3-compiled-Cheat-Sheet-version-3.pdf
PPTX
Python Datatypes by SujithKumar
PDF
A tour of Python
PDF
An overview of Python 2.7
PPTX
Python Workshop
ODP
Intro python
PDF
Python于Web 2.0网站的应用 - QCon Beijing 2010
PPTX
Python Training
PDF
Python for PHP developers
PPTX
Introduction to the basics of Python programming (part 3)
PDF
Introduction to python
PDF
python.pdf
PDF
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PDF
Python lecture 05
PDF
Python-Magnitia-ToC.pdf
PPTX
introductionpart1-160906115340 (1).pptx
PDF
Introduction to Python
PDF
Advanced python
A Few of My Favorite (Python) Things
Python Usage (5-minute-summary)
Python-3-compiled-Cheat-Sheet-version-3.pdf
Python Datatypes by SujithKumar
A tour of Python
An overview of Python 2.7
Python Workshop
Intro python
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python Training
Python for PHP developers
Introduction to the basics of Python programming (part 3)
Introduction to python
python.pdf
PART 3: THE SCRIPTING COMPOSER AND PYTHON
Python lecture 05
Python-Magnitia-ToC.pdf
introductionpart1-160906115340 (1).pptx
Introduction to Python
Advanced python
Ad

Recently uploaded (20)

PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
Trending Python Topics for Data Visualization in 2025
PPTX
Computer Software - Technology and Livelihood Education
PPTX
Cybersecurity: Protecting the Digital World
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
Introduction to Windows Operating System
PDF
Autodesk AutoCAD Crack Free Download 2025
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PDF
AI Guide for Business Growth - Arna Softech
PDF
Visual explanation of Dijkstra's Algorithm using Python
PPTX
GSA Content Generator Crack (2025 Latest)
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Topaz Photo AI Crack New Download (Latest 2025)
Trending Python Topics for Data Visualization in 2025
Computer Software - Technology and Livelihood Education
Cybersecurity: Protecting the Digital World
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Monitoring Stack: Grafana, Loki & Promtail
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Introduction to Windows Operating System
Autodesk AutoCAD Crack Free Download 2025
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Designing Intelligence for the Shop Floor.pdf
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Advanced SystemCare Ultimate Crack + Portable (2025)
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
AI Guide for Business Growth - Arna Softech
Visual explanation of Dijkstra's Algorithm using Python
GSA Content Generator Crack (2025 Latest)
Why Generative AI is the Future of Content, Code & Creativity?
Ad

How to train your python: iterables (FR)

  • 1. Jordi Riera ● Software developer @ Rodeo FX ● Founder @ cgstudiomap.org ● 8 ans à écrire du python ● kender.jr@gmail.com ● @jordiriera_cg ● https://www.linkedin.com/in/jordirieracg/ ● https://github.com/foutoucour/
  • 2. How To Train Your Python Les bases sur les iterables
  • 3. Iterables + de 10 types d’iterables
  • 4. liste, et pas que ● List & deque ● Tuple & namedtuple ● String ● Set & frozenset ● Dict, Ordereddict, ChainMap, Counter & defaultdict ● Generators ● Range, zip, map, file object, et autres.
  • 6. Lequel choisir? ● List, deque, tuple, string, generators, Ordereddict: ordonnés ● Tuple, frozenset: immuables (well... kind of... :( ) ● Set & frozenset: caractère unique ● Dict, Ordereddict, ChainMap, Counter & defaultdict: mapping ● String: ... ben... string quoi... ● Generators, range, zip, map, etc: optimisation, consommation
  • 7. for loop languages = [‘php’, ‘ruby’, ‘python’] frameworks = [‘symfony’, ‘ruby on rails’, ‘django’] for i in range(len(languages)): print(languages[i] + ‘: ’ + frameworks[i])
  • 8. for loop languages = [‘php’, ‘ruby’, ‘python’] frameworks = [‘symfony’, ‘ruby on rails’, ‘django’] for i, language in enumerate(languages): print(‘: ’.join([language, frameworks[i]])) for language, framework in zip(languages, frameworks): print(‘: ’.join([language, framework]))
  • 9. Set random_numbers = [ 3, 4, 4, 1, 2, 3, 1] set(random_numbers) >>> {1, 2, 3, 4} frozenset(random_numbers) >>> frozenset({1, 2, 3, 4})
  • 10. Set Sets acceptent les opérations mathématiques: ● Union ● Intersection ● Difference ● Et d’autres opérations plus chelou, mais ça fait de jolies figures
  • 11. dict, feel the powa!
  • 12. mapping = dict() # ou {} for language, framework in zip(languages, frameworks): if not language in languages: mapping[language] = [] mapping[language].append(framework) dict
  • 13. mapping = defaultdict(list) for language, framework in zip(languages, frameworks): mapping[language].append(framework) mapping = {} for l, framework in zip(languages, frameworks): mapping.setdefault(l, []).append(framework) dict
  • 14. dict mapping = {‘php’:[‘symfony’], ‘ruby’:[’ruby on rails’], ‘python’:[’django’]} for language in mapping: print(language) for language, frameworks in mapping.items(): print(language, frameworks)
  • 15. dict mapping = {‘php’:[‘symfony’], ‘ruby’:[’ruby on rails’], ‘python’:[’django’]} print(mapping[‘python’]) del mapping[‘python’] print(mapping.get(‘python’, ‘flask’)) Mapping[‘python’] = ‘pyramid’
  • 16. muabilité # Les listes sont muables. Elles peuvent être mis à jour: list1 = [1,] list1.append(2) list1 == [1, 2] Et d’autres méthodes... list2 = [1,] list2.insert(0, 2) list2 == [2, 1]
  • 17. muabilité # Cool mais... list2 = list1 list1.append(3) list2 == [1, 2, 3] # list2 “pointe” vers list1. # list1 et list2 sont la même liste en fait...
  • 18. muabilité # Solution list2 = list1[:] # list2 est une liste avec tous les éléments de list1 # you’re welcome ;)
  • 19. # Les tuples sont immuables, # ils ne peuvent pas être mis à jour: tuple1 = (1,) tuple1.append(2) Raise AttributeError immuabilité
  • 20. # enfin... list1 = [1,] tuple1 = (1, list1) list1.append(2) tuple1 == (1, [1, 2]) # pas cool bro! immuabilité
  • 21. Compréhension à la portée de tous! list1 = [x for x in z if not x == ‘foo’] gen = (x for x in z if not x == ‘foo’) # Nope c’est pas un tuple! Mais un générateur. set1 = {x for x in z if not x == ‘foo’} dic1 = {x: x.bar for x in z if not x == ‘foo’}
  • 22. Questions? ● kender.jr@gmail.com ● @jordiriera_cg ● https://www.linkedin.com/in/jordirieracg/ ● https://github.com/foutoucour/

Editor's Notes

  • #8: For est un for each! Zip remplace izip de py2. zip de py2 est mort
  • #9: For est un for each! Zip remplace izip de py2. zip de py2 est mort
  • #10: For est un for each! Zip remplace izip de py2. zip de py2 est mort
  • #11: For est un for each! Zip remplace izip de py2. zip de py2 est mort