Page 204 - Information_Practice_Fliipbook_Class11
P. 204
Output: count of elements
'''
count = 0
for element in ageList :
count += 1
print("Count of friends: ", count)
'''
Objective: To compute the most frequently occuring element (mode) in a list
Input: a list of numbers
Output: mode of the elements of list
'''
frequency = {}
maxCount = 0
mostFrequent = None
for element in ageList:
if element in frequency:
frequency[element] += 1
else:
frequency[element] = 1
if frequency[element] > maxCount:
maxCount = frequency[element]
mostFrequent = element
print("The age value that occurs the most is: ",mostFrequent)
Assessment
A. Multiple Choice Questions
1. Which of the following statements will create an empty list?
a. lst = () b. lst = list() c. lst = empty() d. lst = null_list()
2. What will be the output produced on the execution of the following code:
message = "Never give up"
myList = message.split('e')
print(myList[-2], myList[2])
a. give up b. v r giv c. r giv r giv d. r giv up
3. If lst = [None], what will be the result produced on evaluating the following expression, lst*3?
a. []
b. [[None], [None], [None]]
c. [None, None, None]
d. None
190 Touchpad Informatics Practices-XI

