Lecture4_py776
Lecture4_py776
Apna
They are unordered, mutable(changeable) & don’t allow duplicate keys
College
“key” : value
dict[”name”], dict[”cgpa”],
Apna
College
student[”score”][”math”]
Dictionary Methods
myDict.keys( ) #returns all keys
Apna
myDict.values( ) #returns all values
College
myDict.items( ) #returns all (key, val) pairs as tuples
Apna
Each element in the set must be unique & immutable.
College
nums = { 1, 2, 3, 4 }
set2 = { 1, 2, 2, 2 }
#repeated elements stored only once, so it resolved to {1, 2}
Apna
set.remove( el ) #removes the
College
elem an set.clear( ) #empties the
set
Apna
set.intersection( set2 ) #combines common values & returns new
College
Let‘s Practice
Store following word meanings in a python
Apna
dictionary : table : “a piece of furniture”, “list of facts
College
You are given a list of subjects for students. Assume one classroom is
required for 1 subject. How many classrooms are needed by all students.
Apna
College
Figure out a way to store 9 & 9.0 as separate values in
the set. (You can take help of built-in data types)