0% found this document useful (0 votes)
26 views1 page

Python Dictionary Assignment Guide

The document provides examples of Python dictionary operations including converting lists to a dictionary, merging dictionaries, initializing a dictionary with default values, extracting keys from a dictionary, and checking if a value exists in a dictionary.

Uploaded by

Temporary
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)
26 views1 page

Python Dictionary Assignment Guide

The document provides examples of Python dictionary operations including converting lists to a dictionary, merging dictionaries, initializing a dictionary with default values, extracting keys from a dictionary, and checking if a value exists in a dictionary.

Uploaded by

Temporary
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

Assignment Based on Python Dictionary

1. Below are the two lists. Write a Python program to convert them into a dictionary in a
way that item from list1 is the key and item from list2 is the value
keys = ['Ten', 'Twenty', 'Thirty']
values = [10, 20, 30]
Expected output:
{'Ten': 10, 'Twenty': 20, 'Thirty': 30}
2. Merge two Python dictionaries into one
dict1 = {'Ten': 10, 'Twenty': 20, 'Thirty': 30}
dict2 = {'Thirty': 30, 'Forty': 40, 'Fifty': 50}
Expected output:
{'Ten': 10, 'Twenty': 20, 'Thirty': 30, 'Forty': 40, 'Fifty': 50}
3. Initialize dictionary with default values
Given:
employees = ['Kelly', 'Emma']
defaults = {"designation": 'Developer', "salary": 8000}
Expected output:
{
'Kelly': {'designation': 'Developer', 'salary': 8000},
'Emma': {'designation': 'Developer', 'salary': 8000}
}
4. Write a Python program to create a new dictionary by extracting the mentioned keys from
the below dictionary.
Given dictionary:
sample_dict = {
"name": "Kelly",
"age": 25,
"salary": 8000,
"city": "New york"
}
# Keys to extract
keys = ["name", "salary"]
Expected output:
{'name': 'Kelly', 'salary': 8000}
5. Check if a value exists in a dictionary or not?
Given:
sample_dict = {'a': 100, 'b': 200, 'c': 300}
Expected output:
200 present in a dict

You might also like