Professional Documents
Culture Documents
BSIS-1M-Muhmammad Talha-Assignment 6
BSIS-1M-Muhmammad Talha-Assignment 6
BSIS-1M-Muhmammad Talha-Assignment 6
Q 1.
What is the difference between a set and a list?
SET LIST
Set is a collection which is A list is a collection where you can
unordered and unindexed, and put your values using square
does not allow duplicates. In brackets, which
Python, sets are written with curly is ordered and changeable. You
brackets. can put several data-types in a list,
• You cannot access items in a such as integers, strings, and
set by referring to an index booleans.
• Sets are mutable
• You access the list items by
• They are useful for checking
referring to the index number
for duplicates
• Lists are mutable
Example of Set:
Set OF String = {"one", "two", "three"}
Example Of List:
list =[8, -30, "apple", "20"]
Q 2.
What is the difference between a list and a dictionary?
LIST DICTIONARY
A list is a collection where you can
A dictionary maps hashable values
put your values using square to arbitrary objects. A dictionary
brackets, which is a mutable object. The main
is ordered and changeable. You operations on a dictionary are
can put several data-types in a storing a value with some key and
list, such as integers, strings, and
extracting the value given the
booleans. key..
Example Of Dictionary:
• You access the list items by "age": 24,
referring to the index number "favorite_fruit": "apple"
• Lists are mutable my_dictionary["age"]
Example Of List:
list =[8, -30, "apple", "20"]
Q 8.
Given a dictionary?
gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C": 6 }
write the Python statement(s) to print:
write the Python statement(s) to print:
a) all the keys.
gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C": 6 }
key =gradeCounts.keys()
print(key)
output
dict_keys(['A', 'D', 'B', 'F', 'C'])
b) all the values.
gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C": 6 }
print(gradeCounts)
output
{'A': 8, 'D': 3, 'B': 15, 'F': 2, 'C': 6}
Output:-
dict_values([8, 3, 15, 2, 6])
1
34.0