SlideShare a Scribd company logo
1 of 10
Welcome to Python
Tuple, List, Dictionary
Gimme a definition! → Tuple
• Tuple is one of python data types that categorize
as sequence and it consists of comma-
separated objects like string, number, list and
even another tuple!
• Tuple is immutable, and that’s differ it from list
• Immutable: An object with a fixed value.
Immutable objects include numbers, strings and
tuples. Such an object cannot be altered. A new
object has to be created if a different value has to
be stored. They play an important role in places
where a constant hash value is needed, for
example as a key in a dictionary.(from
docs.python.org)
Examples for Tuple
Try it out !
1 >>> x = ("1", 2, [3])
>>> print(x)
????
>>> type(x)
????
2 >>> a = "1"
>>> b = 2
>>> c = [3]
>>> y = a, b, c
>>> print(y)
????
>>> type(y)
????
3 >>> a = "1"
>>> y = (a)
>>> type(y)
????
>>> a = "1"
>>> y = (a,)
>>> type(y)
????
>>> print(y)
????
>>> print(y[1])
????
>>> len(y)
????
Tuple: Advantages???
• tuple can assigned faster than list. Can you prove it by yourself? (Try to compare with list creation code!)
• Write protected!
• Use less memory than list. Because, tuple is fixed-size and list is variable-sized.
• Can assign as key at dictionary
Tuple: Operations
1. Accessing Values :
• x = (1, 2, 3, 4, 5)
• x[0]
• x[len(x)-1] # or ?
2. Concatenation :
• a = (1, 2, 3)
• b = (4, 5, 6)
• c = a + b
3. Multiply :
• x = ("A",)
• x = x * 2 #??
4. Delete Tuple :
• del x[0] #??
• del x # ??
5. Comparison :
• print((1, 2) == (1, 2))
• print((1, 2) is (1, 2))
 The == operator compares the values of both
the operands and checks for value equality.
Whereas is operator checks whether both the
operands refer to the same object or not.
• x = (1, 2)
• y = x
• print(x is y and x == y) #??
6. The ‘in’ operator:
• x = (1, 2)
• print(1 in x)
• print((1 and 2) in x) # print((1 or 4) in x)
7. ‘sorted’ function with ‘reverse’ parameter
One question?
>>> x = ("1", 2, [3])
>>> print(x)
>>> y = x[2]
>>> y.append(4)
>>> y.append(5)
>>> y.append(6)
>>> print(x)
List = Tuple + something
Additional to tuples:
• sort:
• x=[5,6,2,3,5]
• x.sort()
• reserve:
• x.reverse()
• copy:
• x = [1,3,6]
• y=x
• z=x.copy()
• y[1] = 888
• print(x[1]) #???
• print(z[1]) #???
• List as stack:
• append() and pop()
• del stands for delete
 What is lambda?
 What is list comprehension?!
Dictionary, Are you looking up for something?
• Dictionary consists of two main part:
• Key: What is you will save and retrieve
value with
• Value: What you want to hide with Key
• Why we used hide in above sentences?
• For creating dictionary just use this pattern:
• ‘[key]’:[value] like bellow:
• d = {‘name’:’some thing’,’age’:150}
• How to get ‘some thing’ back??
• d[0] or d[‘name’] or …
• There is no order in saving values for keys
(unlike list)
• Can we say list is a dictionary with ordered
integer as key?
• There is another way to build dictionary
with dict() constructor:
• dict([('sape', 4139), ('guido', 4127), ('jack',
4098)])
Dictionary
• Looping through dictionary elements:
• knights = {'gallahad': 'the pure', 'robin':
'the brave'}
• for k, v in knights.items():#(key,value)
• for v in knights.values():
• for k in knights.keys():
• zip:
• For making dictionary out of 2 list with
same size:
• questions = ['name', 'quest', 'favorite
color']
• answers = ['lancelot', 'the holy grail',
'blue']
• for a,b in zip(questions,answers):
• print("%s = %s" % (a,b))
• enumerate: (a way to make list!)
• for i, v in enumerate([‘ali’,’jack’]:
Link to source
https://docs.python.org/3/tutorial/datastructures.html
https://www.w3schools.com/python/

More Related Content

What's hot (20)

Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Chapter 16 Dictionaries
Chapter 16 DictionariesChapter 16 Dictionaries
Chapter 16 Dictionaries
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Dictionaries and Sets in Python
Dictionaries and Sets in PythonDictionaries and Sets in Python
Dictionaries and Sets in Python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Groovy
GroovyGroovy
Groovy
 
1. python
1. python1. python
1. python
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
List in Python
List in PythonList in Python
List in Python
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 

Similar to An Introduction to Tuple List Dictionary in Python

UNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptxUNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptxNishanSidhu2
 
Brixton Library Technology Initiative
Brixton Library Technology InitiativeBrixton Library Technology Initiative
Brixton Library Technology InitiativeBasil Bibi
 
Ch 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptxCh 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptxKanchanaRSVVV
 
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptxLecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptxlokeshgoud13
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Simplilearn
 
Well Grounded Python Coding - Revision 1 (Day 1 Slides)
Well Grounded Python Coding - Revision 1 (Day 1 Slides)Well Grounded Python Coding - Revision 1 (Day 1 Slides)
Well Grounded Python Coding - Revision 1 (Day 1 Slides)Worajedt Sitthidumrong
 
Well Grounded Python Coding - Revision 1 (Day 1 Handouts)
Well Grounded Python Coding - Revision 1 (Day 1 Handouts)Well Grounded Python Coding - Revision 1 (Day 1 Handouts)
Well Grounded Python Coding - Revision 1 (Day 1 Handouts)Worajedt Sitthidumrong
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developersJim Roepcke
 
Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014Reuven Lerner
 
Advanced geoprocessing with Python
Advanced geoprocessing with PythonAdvanced geoprocessing with Python
Advanced geoprocessing with PythonChad Cooper
 
Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1Vikram Nandini
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like PythonistaChiyoung Song
 
Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...gjcross
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxGaneshRaghu4
 
Getting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGetting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGDSCKYAMBOGO
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3Ahmet Bulut
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 

Similar to An Introduction to Tuple List Dictionary in Python (20)

UNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptxUNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptx
 
Brixton Library Technology Initiative
Brixton Library Technology InitiativeBrixton Library Technology Initiative
Brixton Library Technology Initiative
 
Ch 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptxCh 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptx
 
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptxLecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
 
Well Grounded Python Coding - Revision 1 (Day 1 Slides)
Well Grounded Python Coding - Revision 1 (Day 1 Slides)Well Grounded Python Coding - Revision 1 (Day 1 Slides)
Well Grounded Python Coding - Revision 1 (Day 1 Slides)
 
Well Grounded Python Coding - Revision 1 (Day 1 Handouts)
Well Grounded Python Coding - Revision 1 (Day 1 Handouts)Well Grounded Python Coding - Revision 1 (Day 1 Handouts)
Well Grounded Python Coding - Revision 1 (Day 1 Handouts)
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developers
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014
 
Advanced geoprocessing with Python
Advanced geoprocessing with PythonAdvanced geoprocessing with Python
Advanced geoprocessing with Python
 
Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptx
 
Getting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGetting started in Python presentation by Laban K
Getting started in Python presentation by Laban K
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 

Recently uploaded

AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfryanfarris8
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...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 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 

Recently uploaded (20)

AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
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 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 

An Introduction to Tuple List Dictionary in Python

  • 1. Welcome to Python Tuple, List, Dictionary
  • 2. Gimme a definition! → Tuple • Tuple is one of python data types that categorize as sequence and it consists of comma- separated objects like string, number, list and even another tuple! • Tuple is immutable, and that’s differ it from list • Immutable: An object with a fixed value. Immutable objects include numbers, strings and tuples. Such an object cannot be altered. A new object has to be created if a different value has to be stored. They play an important role in places where a constant hash value is needed, for example as a key in a dictionary.(from docs.python.org)
  • 3. Examples for Tuple Try it out ! 1 >>> x = ("1", 2, [3]) >>> print(x) ???? >>> type(x) ???? 2 >>> a = "1" >>> b = 2 >>> c = [3] >>> y = a, b, c >>> print(y) ???? >>> type(y) ???? 3 >>> a = "1" >>> y = (a) >>> type(y) ???? >>> a = "1" >>> y = (a,) >>> type(y) ???? >>> print(y) ???? >>> print(y[1]) ???? >>> len(y) ????
  • 4. Tuple: Advantages??? • tuple can assigned faster than list. Can you prove it by yourself? (Try to compare with list creation code!) • Write protected! • Use less memory than list. Because, tuple is fixed-size and list is variable-sized. • Can assign as key at dictionary
  • 5. Tuple: Operations 1. Accessing Values : • x = (1, 2, 3, 4, 5) • x[0] • x[len(x)-1] # or ? 2. Concatenation : • a = (1, 2, 3) • b = (4, 5, 6) • c = a + b 3. Multiply : • x = ("A",) • x = x * 2 #?? 4. Delete Tuple : • del x[0] #?? • del x # ?? 5. Comparison : • print((1, 2) == (1, 2)) • print((1, 2) is (1, 2))  The == operator compares the values of both the operands and checks for value equality. Whereas is operator checks whether both the operands refer to the same object or not. • x = (1, 2) • y = x • print(x is y and x == y) #?? 6. The ‘in’ operator: • x = (1, 2) • print(1 in x) • print((1 and 2) in x) # print((1 or 4) in x) 7. ‘sorted’ function with ‘reverse’ parameter
  • 6. One question? >>> x = ("1", 2, [3]) >>> print(x) >>> y = x[2] >>> y.append(4) >>> y.append(5) >>> y.append(6) >>> print(x)
  • 7. List = Tuple + something Additional to tuples: • sort: • x=[5,6,2,3,5] • x.sort() • reserve: • x.reverse() • copy: • x = [1,3,6] • y=x • z=x.copy() • y[1] = 888 • print(x[1]) #??? • print(z[1]) #??? • List as stack: • append() and pop() • del stands for delete  What is lambda?  What is list comprehension?!
  • 8. Dictionary, Are you looking up for something? • Dictionary consists of two main part: • Key: What is you will save and retrieve value with • Value: What you want to hide with Key • Why we used hide in above sentences? • For creating dictionary just use this pattern: • ‘[key]’:[value] like bellow: • d = {‘name’:’some thing’,’age’:150} • How to get ‘some thing’ back?? • d[0] or d[‘name’] or … • There is no order in saving values for keys (unlike list) • Can we say list is a dictionary with ordered integer as key? • There is another way to build dictionary with dict() constructor: • dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
  • 9. Dictionary • Looping through dictionary elements: • knights = {'gallahad': 'the pure', 'robin': 'the brave'} • for k, v in knights.items():#(key,value) • for v in knights.values(): • for k in knights.keys(): • zip: • For making dictionary out of 2 list with same size: • questions = ['name', 'quest', 'favorite color'] • answers = ['lancelot', 'the holy grail', 'blue'] • for a,b in zip(questions,answers): • print("%s = %s" % (a,b)) • enumerate: (a way to make list!) • for i, v in enumerate([‘ali’,’jack’]:

Editor's Notes

  1. In Slide Show mode, select the arrows to visit links.