Join Our WhatsApp Group Join Subscribe Now!

Basic Python Programming (313011) Practical No.9: Create a program to perform following operations on Dictionaries in Python: a) Create b) Access c) Update d) Delete e) Looping through Dictionary

Basic Python Programming (313011) Practical No.9: Create a program to perform following operations on Dictionaries in Python: a) Create b) Access c) U

 Basic Python Programming (313011) Practical No.9: Create a program to perform the following operations on Dictionaries in Python: a) Create b) Access c) Update d) Delete e) Looping through Dictionary

Python dictionaries allow us to associate a value to a unique key, and then to quickly access this value. Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is ordered, changeable and does not allow duplicates.

Practical related Questions

1. Write the output of the following program.

dict = {1:"Photodiode", 2:"Zener diode", 3:" Schottky diode",4: "P-N junction diode"}
del dict[1];
for key, val in dict.items():
print(key)
for key, val in dict.items():
print(key,values)
del dictionary:
for key, val in dict.items():
print(key)

Answer:

2
3
4
2 Zener diode
3  Schottky diode
4 P-N junction diode

2. Write the output of the following program.

dict1 = {'Amplifiers': ‘BJT’, 'Transistor': ‘PNP’}
dict2 = {'FET':10, 'MOSFET': 5}
dict1.update(dict2)
print(dict1)

Answer:

{'Amplifiers': 'BJT', 'Transistor': 'PNP', 'FET': 10, 'MOSFET': 5}

Exercise

1. Write a Python script to iterate over dictionaries using for loops.

Answer:


2. Write a Python script to change the value of a dictionary element by referring to its key.

Answer:



About the Author

Hi everyone, I'm Suraj Diware, and I'm passionate about helping students succeed in MSBTE programs. This blog is dedicated to providing clear and concise explanations of MSBTE curriculum topics, along with practical tips and resources to sup…

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.