Working with List and Dictionary
Krishan Meena
JAWAHAR NAVODAYA VIDYALAYA PUDUCHERRY
LIST
[ ]
,
List samples
Types of list
Types of list
Types of list
Creating list from existing sequence
Creating list from existing sequence
Creating list from existing sequence
Creating list by user input
Creating list by user input
Accessing list element
Indexing
Accessing list elements
Forward
Indexing
Backward
Indexing
List
Length of the list
Quiz: 1
Indexing and slicing list
Indexing and slicing list
Indexing and slicing list
We have to ignore
End limit value
Quiz : 2
Membership operators
Concatenation and replication operators
Quiz: 3
Quiz: 4
Quiz: 5
* operator
Slicing list
List updating
Working with list (Appending, updating, deleting on list)
Value
added
At last
Index number
New value
Updated value
Quiz: 6
List functions and methods
.index() function
.index() function
.index() function
.index() function
.index() function
List.extend() function
List.extend() function
Original list1 data
list1 Data after extend
Original list2 data
.insert() method
.insert() method
.insert() method
.pop() function
Deleted item
Home work
Quiz: 7
.remove()
.remove()
Removed
What if item does not exist?
What if item exist twice?
First occurrence will be removed not all.
.clear() function
If you enter a value in clear brackets.
.count() function
.count() function
Upper case and lower case treated differently
.count() function
.reverse() function
.reverse() function
.reverse() function
.sort() function
.sort() function
Sorting in decreasing order
Sorting in decreasing order
Comparing Lists:
Comparing Lists:
Two different lists
Comparing Lists:
Same values in both lists
Dictionaries
Creating dictionary
Dictionary variable name
Dictionary keys
are unique
Dictionary values
Creating dictionary
Creating dictionary
Creating dictionary
Creating dictionary
Creating dictionary
Examples (Invalid Dictionaries):�
# Key is mutable type – list
# Key is mutable type
– Dictionary in First Item
Accessing element of dictionary
Membership Operators
Membership Operators
Membership Operators
Membership Operators
Traversing a dictionary
Traversing a dictionary
Traversing a dictionary
Quiz: 8
Characteristic of dictionary
Updating key:value
Updating key:value
Deleting element from dic
Dictionary Functions and Methods:
1. len( ) :�
Dictionary Functions and Methods:
2. get( ) �
2. get( ) �
Dictionary Functions and Methods:
3. update( ) :�
Updated values
Dictionary Functions and Methods:
Dictionary Functions and Methods:
Ans:1
Ans: 2
Ans: 3
Ans: 4
Ans: 5
Ans: 6
Ans: 7
Ans:7
Ans: 7
Ans:7
Ans: 8
Thank you