SlideShare a Scribd company logo
PART 2
LISTS IN PYTHON
• WANT TO LEARN PYTHON PROGRAMMING? (SUBTITLES)
• SUBSCRIBE
• TELEGRAM – FreeCodeSchool
• Twitter – shivammitra4
• LinkedIn – shivammitra
• Link in description
• INSTALLING PYTHON
• VARIABLES AND DATA TYPES
• PLAYLIST LINK IN DESCRIPTION
STORING MULTIPLE NAMES ?
• 5 names, 10 names …. 100 names
• Storing it in strings doesn’t scale well
• Storing multiple numbers
• Code clarity
• Slow access
INTRODUCING LISTS
• A list is a collection of items in a particular order
• List of
• Names
• Places
• list of digits
• list of colors
• Good to name your list names as plurals – names, places etc
LISTS IN PYTHON
• Use square brackets ([]) to represent a list
• Individuals elements are separated by a comma
• Printing a list
ACCESSING ELEMENTS IN A LIST
• Lists are ordered
• Access an element by its position or index
• In Python and most languages, list numbering starts from 0th position
• This is very important
USE STRING METHODS ON THESE ELEMENTS
REMEMBER THIS IMPORTANT THING
• Each index in a list contains a data type – integers, float, strings etc
• Instead to using multiple variable names, you are using a single
variable name to store all these
• All functions/operations on a data type applies here to elements
CAN WE STORE DIFFERENT DATA TYPES IN A
LIST ?
But mostly we will store same type of data
LENGTH OF THE LIST USING LEN() FUNCTION
ACCESSING LAST ELEMENTS IN A LIST
NEGATIVE INDEXING IN PYTHON
THIS WILL BE FASTER THAN THE LAST METHOD
STRINGS VS LISTS IN PYTHON
MODIFYING AN ELEMENT - LIST VS STRING
MUTABLE VS IMMUTABLE DATA TYPES
• Immutable data type
• The value/data cannot be changed
• Example: strings, integers, floats etc
• Mutable data type
• The value/data can be changed
• Example – lists
• More about this in a separate video
INSERTING ELEMENTS
TO A LIST
INSERTING ELEMENTS AT THE END OF A LIST
• This is very common
• As data is mostly known after the program starts running
INSERTING ELEMENTS AT ANY POSITION
Part 2 - Python Tutorial | Introduction to Lists
REMOVING ELEMENTS
FROM A LIST
REMOVING USING DEL STATEMENTS
REMOVING USING POP METHOD
• The pop() method removes the last item in a list, but it lets you work
with that item after removing it
POPPING ITEMS FROM ANY POSITION IN THE
LIST
WHEN TO USE DEL VS POP ?
REMOVING AN ELEMENT BY VALUE
REMOVING AN ELEMENT NOT IN A LIST
CAN DUPLICATES BE REMOVED ?
• Removes first matching value
• USING REMOVE AGAIN WILL DO
ORGANIZING A LIST
SORTING A LIST
• Putting the elements in a particular order
• Increasing order
• Decreasing order
• Numbers = [2, 1, 3]
• Increasing = [1, 2, 3]
• Decreasing = [3, 2, 1]
SORTING A LIST OF STRINGS
• Alphabetical order
• Names = [‘Shivam’, ’Anil’, ‘Navneet’]
• Increasing alphabetical order = [‘Anil’, ‘Navneet’, ‘Shivam’]
• Decreasing alphabetical order = [‘Shivam’, ‘Navneet’, ‘Anil’]
SORTING A LIST PERMANENTLY WITH SORT
FUNCTION
BY DEFAULT, SORT() SHORTES IN INCREASING ORDER
SORTING IN REVERSE ALPHABETIC ORDER
Part 2 - Python Tutorial | Introduction to Lists
SORTING A LIST TEMPORARILY WITH SORTED
FUNCTION
• To maintain the original order of a list but present it in a sorted order,
you can use the sorted() function.
• The sorted() function lets you display your list in a particular order but
doesn’t affect the actual order of the list.
Part 2 - Python Tutorial | Introduction to Lists
PRINTING A LIST IN REVERSE ORDER
What if you reverse again ?
AVOIDING INDEX ERRORS WHEN WORKING
WITH LIST
REMEMBER THAT INDEXING STARTS AT 0
Part 2 - Python Tutorial | Introduction to Lists
FOR LOOP IN PYTHON
AND USING LISTS

More Related Content

PPTX
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PPTX
PART 4 - Python Tutorial | If Else In Python With Examples
PPTX
PART 3 - Python Tutorial | For Loop In Python With Examples
PPTX
PART 10 - Python Tutorial | Functions In Python With Examples
PPTX
PART 9 - Python Tutorial | While Loop In Python With Examples
PPTX
PART 1 - Python Tutorial | Variables and Data Types in Python
PPTX
Python Tutorial Part 1
PDF
Python Programming
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 10 - Python Tutorial | Functions In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 1 - Python Tutorial | Variables and Data Types in Python
Python Tutorial Part 1
Python Programming

What's hot (20)

PDF
Python libraries
PPTX
Basic data types in python
PPTX
List in Python
PPTX
User defined function in c
PDF
2. python basic syntax
PPTX
Python basics
PPTX
Tuple in python
PPTX
Python Basics
PDF
Python basic
PPTX
Python Flow Control
PDF
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
PPT
Pointers C programming
PPTX
Python programming
PDF
Variables & Data Types In Python | Edureka
DOCX
Python Applications
PPT
Exception handling and function in python
PPTX
Basic Python Programming: Part 01 and Part 02
PPTX
Recursion
PPTX
Linked list
PPTX
Lecture 01 Intro to DSA
Python libraries
Basic data types in python
List in Python
User defined function in c
2. python basic syntax
Python basics
Tuple in python
Python Basics
Python basic
Python Flow Control
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
Pointers C programming
Python programming
Variables & Data Types In Python | Edureka
Python Applications
Exception handling and function in python
Basic Python Programming: Part 01 and Part 02
Recursion
Linked list
Lecture 01 Intro to DSA
Ad

Similar to Part 2 - Python Tutorial | Introduction to Lists (17)

PPTX
Python programming
PPTX
Linked List
PPTX
Lists Data Structures and Algorithm.pptx
PPTX
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
PPTX
Stack and queue power point presentation data structure and algorithms Stack-...
PPTX
PYTHON DATA TYPE in python using v .pptx
PPTX
PYTHON DATA TYPE IN PROGRAMMING LANG.pptx
PDF
Apl – a programming language
PPTX
Data structures2
PPT
2- link-list.ppt
PPTX
Introduction to lists
PPTX
Computer Sience, This is my presentation for beginners coding in python
PDF
"Automata Basics and Python Applications"
PPTX
MODULE-2.pptx
PPTX
PPTX
ds bridge.pptx
PPTX
3_Lists.pptxbnchfjgjkghjvghcghchgjhhkhjh
Python programming
Linked List
Lists Data Structures and Algorithm.pptx
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
Stack and queue power point presentation data structure and algorithms Stack-...
PYTHON DATA TYPE in python using v .pptx
PYTHON DATA TYPE IN PROGRAMMING LANG.pptx
Apl – a programming language
Data structures2
2- link-list.ppt
Introduction to lists
Computer Sience, This is my presentation for beginners coding in python
"Automata Basics and Python Applications"
MODULE-2.pptx
ds bridge.pptx
3_Lists.pptxbnchfjgjkghjvghcghchgjhhkhjh
Ad

More from Shivam Mitra (15)

PPTX
Preparing for SRE Interviews
PPTX
PART 8 - Python Tutorial | User Input In Python With Examples
PPTX
PART 6 - Python Tutorial | Tuples In Python With Examples
PPTX
PART 0 - Python Tutorial | Why should you learn python
PPTX
Memory management in operating system | Paging | Virtual memory
PPTX
Process Synchronization in operating system | mutex | semaphore | race condition
PPTX
Process Scheduling Algorithms | Interviews | Operating system
PPTX
Threads in Operating System | Multithreading | Interprocess Communication
PPTX
Process management in operating system | process states | PCB | FORK() | Zomb...
PPTX
Introduction to operating system, system calls and interrupts
PPTX
What is Internet and How it Works
PPTX
OSI Model Layers and Internet Protocol Stack
PPTX
Basics of Stock Market
PPTX
Assets vs liability
PPTX
Pycricbuzz - a python library to fetch live cricket scores
Preparing for SRE Interviews
PART 8 - Python Tutorial | User Input In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 0 - Python Tutorial | Why should you learn python
Memory management in operating system | Paging | Virtual memory
Process Synchronization in operating system | mutex | semaphore | race condition
Process Scheduling Algorithms | Interviews | Operating system
Threads in Operating System | Multithreading | Interprocess Communication
Process management in operating system | process states | PCB | FORK() | Zomb...
Introduction to operating system, system calls and interrupts
What is Internet and How it Works
OSI Model Layers and Internet Protocol Stack
Basics of Stock Market
Assets vs liability
Pycricbuzz - a python library to fetch live cricket scores

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
Renaissance Architecture: A Journey from Faith to Humanism
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Open folder Downloads.pdf yes yes ges yes
2.FourierTransform-ShortQuestionswithAnswers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
TR - Agricultural Crops Production NC III.pdf
Cardiovascular Pharmacology for pharmacy students.pptx
Pharma ospi slides which help in ospi learning
Introduction and Scope of Bichemistry.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Anesthesia in Laparoscopic Surgery in India
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
102 student loan defaulters named and shamed – Is someone you know on the list?
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Basic Mud Logging Guide for educational purpose
Week 4 Term 3 Study Techniques revisited.pptx

Part 2 - Python Tutorial | Introduction to Lists

  • 1. PART 2 LISTS IN PYTHON • WANT TO LEARN PYTHON PROGRAMMING? (SUBTITLES) • SUBSCRIBE • TELEGRAM – FreeCodeSchool • Twitter – shivammitra4 • LinkedIn – shivammitra • Link in description • INSTALLING PYTHON • VARIABLES AND DATA TYPES • PLAYLIST LINK IN DESCRIPTION
  • 2. STORING MULTIPLE NAMES ? • 5 names, 10 names …. 100 names • Storing it in strings doesn’t scale well • Storing multiple numbers • Code clarity • Slow access
  • 3. INTRODUCING LISTS • A list is a collection of items in a particular order • List of • Names • Places • list of digits • list of colors • Good to name your list names as plurals – names, places etc
  • 4. LISTS IN PYTHON • Use square brackets ([]) to represent a list • Individuals elements are separated by a comma • Printing a list
  • 5. ACCESSING ELEMENTS IN A LIST • Lists are ordered • Access an element by its position or index • In Python and most languages, list numbering starts from 0th position • This is very important
  • 6. USE STRING METHODS ON THESE ELEMENTS
  • 7. REMEMBER THIS IMPORTANT THING • Each index in a list contains a data type – integers, float, strings etc • Instead to using multiple variable names, you are using a single variable name to store all these • All functions/operations on a data type applies here to elements
  • 8. CAN WE STORE DIFFERENT DATA TYPES IN A LIST ? But mostly we will store same type of data
  • 9. LENGTH OF THE LIST USING LEN() FUNCTION
  • 11. NEGATIVE INDEXING IN PYTHON THIS WILL BE FASTER THAN THE LAST METHOD
  • 12. STRINGS VS LISTS IN PYTHON
  • 13. MODIFYING AN ELEMENT - LIST VS STRING
  • 14. MUTABLE VS IMMUTABLE DATA TYPES • Immutable data type • The value/data cannot be changed • Example: strings, integers, floats etc • Mutable data type • The value/data can be changed • Example – lists • More about this in a separate video
  • 16. INSERTING ELEMENTS AT THE END OF A LIST
  • 17. • This is very common • As data is mostly known after the program starts running
  • 18. INSERTING ELEMENTS AT ANY POSITION
  • 21. REMOVING USING DEL STATEMENTS
  • 22. REMOVING USING POP METHOD • The pop() method removes the last item in a list, but it lets you work with that item after removing it
  • 23. POPPING ITEMS FROM ANY POSITION IN THE LIST
  • 24. WHEN TO USE DEL VS POP ?
  • 26. REMOVING AN ELEMENT NOT IN A LIST
  • 27. CAN DUPLICATES BE REMOVED ? • Removes first matching value • USING REMOVE AGAIN WILL DO
  • 29. SORTING A LIST • Putting the elements in a particular order • Increasing order • Decreasing order • Numbers = [2, 1, 3] • Increasing = [1, 2, 3] • Decreasing = [3, 2, 1]
  • 30. SORTING A LIST OF STRINGS • Alphabetical order • Names = [‘Shivam’, ’Anil’, ‘Navneet’] • Increasing alphabetical order = [‘Anil’, ‘Navneet’, ‘Shivam’] • Decreasing alphabetical order = [‘Shivam’, ‘Navneet’, ‘Anil’]
  • 31. SORTING A LIST PERMANENTLY WITH SORT FUNCTION BY DEFAULT, SORT() SHORTES IN INCREASING ORDER
  • 32. SORTING IN REVERSE ALPHABETIC ORDER
  • 34. SORTING A LIST TEMPORARILY WITH SORTED FUNCTION • To maintain the original order of a list but present it in a sorted order, you can use the sorted() function. • The sorted() function lets you display your list in a particular order but doesn’t affect the actual order of the list.
  • 36. PRINTING A LIST IN REVERSE ORDER What if you reverse again ?
  • 37. AVOIDING INDEX ERRORS WHEN WORKING WITH LIST REMEMBER THAT INDEXING STARTS AT 0
  • 39. FOR LOOP IN PYTHON AND USING LISTS