SlideShare une entreprise Scribd logo
1  sur  22
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/

Contenu connexe

Similaire à How to train your python: iterables (FR)

Introduction to Spark Datasets - Functional and relational together at last
Introduction to Spark Datasets - Functional and relational together at lastIntroduction to Spark Datasets - Functional and relational together at last
Introduction to Spark Datasets - Functional and relational together at lastHolden Karau
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?lichtkind
 
R and Python, A Code Demo
R and Python, A Code DemoR and Python, A Code Demo
R and Python, A Code DemoVineet Jaiswal
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Jonathan Felch
 
Introduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUGIntroduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUGAdam Kawa
 
Deep learning - the conf br 2018
Deep learning - the conf br 2018Deep learning - the conf br 2018
Deep learning - the conf br 2018Fabio Janiszevski
 
A fast introduction to PySpark with a quick look at Arrow based UDFs
A fast introduction to PySpark with a quick look at Arrow based UDFsA fast introduction to PySpark with a quick look at Arrow based UDFs
A fast introduction to PySpark with a quick look at Arrow based UDFsHolden Karau
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonRalf Gommers
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Spaceramanjosan
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in RSamuel Bosch
 
Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Ivan Chernoff
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOLiran Zvibel
 
190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pub190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pubJaewook. Kang
 

Similaire à How to train your python: iterables (FR) (20)

Introduction to Spark Datasets - Functional and relational together at last
Introduction to Spark Datasets - Functional and relational together at lastIntroduction to Spark Datasets - Functional and relational together at last
Introduction to Spark Datasets - Functional and relational together at last
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?
 
R and Python, A Code Demo
R and Python, A Code DemoR and Python, A Code Demo
R and Python, A Code Demo
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
Experimental dtrace
Experimental dtraceExperimental dtrace
Experimental dtrace
 
R - the language
R - the languageR - the language
R - the language
 
Introduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUGIntroduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUG
 
Deep learning - the conf br 2018
Deep learning - the conf br 2018Deep learning - the conf br 2018
Deep learning - the conf br 2018
 
Dafunctor
DafunctorDafunctor
Dafunctor
 
A fast introduction to PySpark with a quick look at Arrow based UDFs
A fast introduction to PySpark with a quick look at Arrow based UDFsA fast introduction to PySpark with a quick look at Arrow based UDFs
A fast introduction to PySpark with a quick look at Arrow based UDFs
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Space
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
 
Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pub190111 tf2 preview_jwkang_pub
190111 tf2 preview_jwkang_pub
 

Dernier

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 

Dernier (20)

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 

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/

Notes de l'éditeur

  1. For est un for each! Zip remplace izip de py2. zip de py2 est mort
  2. For est un for each! Zip remplace izip de py2. zip de py2 est mort
  3. For est un for each! Zip remplace izip de py2. zip de py2 est mort
  4. For est un for each! Zip remplace izip de py2. zip de py2 est mort