Professional Documents
Culture Documents
ASSIGNMENT2 22000423 Visha
ASSIGNMENT2 22000423 Visha
ASSIGNMENT2 22000423 Visha
ASSIGNMENT-1
Practial-1
Aim: Python program to create a dictionary with employee details and retrieve the
values upon giving the keys.
Input:
employee={}
for i in range(a):
employee[empid]=name,salary,phno
print(employee)
for i in employee.keys():
if i==b:
print(employee[i])
1
CS-194,Problem solving using python lab 22000423,Visha Jain
Output:
2
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-2
Aim: Python program to retrieve keys, values, and key-value pairs from a
dictionary
Input:
dict1={}
for i in range(a):
dict1[color]=color_code
keys = dict1.keys()
print("Keys:", keys)
values = dict1.values()
print("Values:", values)
key_value_pairs = dict1.items()
Output:
3
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-3
print(dict1["green"])
dict1["red"] =105
print(dict1)
dict1["purple"] = 202
print(dict1)
del dict1["green"]
print(dict1)
Output:
4
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-4
Aim: Python program to create a dictionary (with cricket player’s names and
scores in the match) from keyboard and display the elements. Also retrieves runs
Input:
s = {}
for i in range(players):
s[name] = score
p_name = input("Enter the name of the player whose score you want to retrieve: ")
if p_name in s:
else:
5
CS-194,Problem solving using python lab 22000423,Visha Jain
Output:
6
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-5
Aim: Python program to find the number of occurrences of each letter in a string
using dictionary
Input:
a=input("enter a string:")
dict1={}
for i in a:
if i in dict1:
dict1[i] += 1
else:
dict1[i] = 1
Output:
7
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-6
Aim: Python program to sort the elements of a dictionary based on a key or value.
Input:
sortkeys = sorted(d.items())
Output:
8
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-7
Aim: Python program to find the sum of all items in a dictionary
Input:
svalues = sum(dict1.values())
skeys=sum(dict1.keys())
Output:
9
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-8
Input:
d3 = {**d1, **d2}
Output:
10
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-9
Aim:Python Program to Count the Frequency of Words Appearing in a String
Using a Dictionary.
Input:
words = s.split()
count = {}
if word in count:
count[word] += 1
else:
count[word] = 1
Output:
11
CS-194,Problem solving using python lab 22000423,Visha Jain
PRACTICAL-10
Aim:Python Program to Convert Two Lists into a Dictionary
Input:
values = [5, 2, 4, 1]
d = dict(zip(keys, values))
print("Dictionary:", d)
Output:
12