Professional Documents
Culture Documents
www.tvtc.gov.sa
Dictionaries
1
11/28/2021
Dictionaries
• Dictionaries are used to store data values in
key : value pairs.
• A dictionary is a collection which is ordered, changeable
and does not allow duplicates.
• Creating a dictionary is as simple as placing items inside curly braces {}
separated by commas.
• An item has a key and a corresponding value that is expressed as a pair
(key: value).
Dictionaries
2
11/28/2021
3
11/28/2021
4
11/28/2021
You can use the built-in len function to get the number of elements in a
dictionary
5
11/28/2021
6
11/28/2021
7
11/28/2021
Dictionary Methods
• The keys() method will return a list of all the keys in the dictionary.
• The values() method will return a list of all the values in the
dictionary.
Dictionary Methods
8
11/28/2021
SETS
sets
9
11/28/2021
Creating a Set
Creating a Set
10
11/28/2021
Creating a Set
For example, how would you create a set containing the elements 'one', 'two', and 'three'?
The following code does not accomplish the task, because you can pass no more than one
argument to the set function:
11
11/28/2021
12
11/28/2021
13
11/28/2021
العنوان الفرعي
14