0% found this document useful (0 votes)
8 views3 pages

Dictionary

Uploaded by

hopeless2693
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Dictionary

Uploaded by

hopeless2693
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PYTHON-DICTIONARY

Program 8.44:
Write a program that has dictionary of names of
students and a list of their marks in 4 subjects. Create
another dictionary from this dictionary that has the
names of the students and their total marks. Find out
the topper and his/her score.

Python Code
marks = {'Neha': [97, 89, 94, 90], 'Mitul': [92, 91, 94, 87], 'Shefali': [67, 99, 88, 90]}
print("The marks of each student is:", marks)
total = 0
new_marks = {}
for i in marks:
b = marks[i]
for j in b:
total = total + j
new_marks[i] = total
total = 0
print("The total marks of each student: ", new_marks)
maxvalue = max(new_marks.values())
maxkey = max(new_marks, key=new_marks.get)
print("The topper of the class is", maxkey, "with total mark", maxvalue)

Output
The mark of each student is: {'Neha': [97, 89, 94, 90],
'Mitul': [92, 91, 94, 87], 'Shefali': [67, 99, 88, 90]}
The total marks of each student: {'Neha': 370, 'Mitul': 364,
'Shefali': 344}
The topper of the class is Neha with total mark 370.
Exercise 11:

Write a program that prompts user to enter a string and


returns in a alphabetical order, a letter and its
frequency of occurrence in the string. (Ignore case).
Python Code
string = input("Please enter your string: ")
listal = []
for i in string:
listal.append(i)
listdup = []
for j in listal:
if j not in listdup:
listdup.append(j)
listdup.sort()
print("The string in alphabetical order is: ", listdup)
countlist = []
count = 0
for a in listdup:
for b in listal:
if a == b:
count += 1
else:
continue
countlist.append(count)
count = 0
string_dict = {}
for x in range(len(listdup)):
string_dict.update({listdup[x]:countlist[x]})
print("The frequency of each letter:", string_dict)

Output:
Please enter your string: apple
The string in alphabetical order is: ['a', 'e', 'l', 'p']
The frequency of each letter: {'a': 1, 'e': 1, 'l': 1, 'p': 2}

You might also like