Skip to content

Latest commit

 

History

History
81 lines (80 loc) · 1.52 KB

48. Unit 4 - Lesson 9.md

File metadata and controls

81 lines (80 loc) · 1.52 KB

Introduction to Dictionaries

Q1. 3,5
Q2. 3,4

Basic Dictionary Operations

Q1.

mydict = {"name":"Rama", "branch":"CSE", "place":"HYD"}
print(mydict["name"])
print(mydict["branch"])
print(mydict["place"])
# Print the values of dictionary using keys

Q2.

mydict = {"game":"chess","dish":"chicken","place":"home"}
print(mydict['game'])
print(mydict['dish'])
print(mydict['place'])
mydict['game'] = "cricket" # change game chess to cricket using respective key
print(mydict['game'])

Q3. 1,2,4
Q4.

# Write your code here
a=input("data1: ").split(",")
b=input("data2: ").split(",")
print("list1:",a)
print("list2:",b)
dict1=dict(zip(a,b))
print("dictionary:",sorted(dict1.items()))

Q5.

a=input('data1: ').split(",")
b=input('data2: ').split(",")
if len(a)==len(b):
	x=dict(zip(a,b))
	print(sorted(x.items()))
else:
	print("length should be equal")

Q6. Need Solution
Q7.

a=input("data1: ").split(",")
b=input("data2: ").split(",")
k=input("key: ")
c=dict(zip(a,b))
print(k in c)

Q8. Need Solution
Q9. Need Solution
Q10.

a=input("data1: ").split(",")
b=input("data2: ").split(",")
k=input("key: ")
c=dict(zip(a,b))
if k in c:
	print("value:",c[k])
	del c[k]
	print("dictionary:",sorted(c.items()))
else:
	print("key does not exist")

Q11.

data1 = input("data1: ")
data2 = input("data2: ")
list1 = data1.split(",")
list2 = data2.split(",")
dict1 = dict(zip(list2, list1))
dict1=sorted(dict1)
print("max:",max(dict1))
print("min:",min(dict1))

Q12. Need Solution