Dictionary Assignments
Dictionary Creations
Creat a dictionary using user input.
Create a dictionary using user input. employee_dict={ 'name' : [ 'john' , 'mike' , 'sara'], 'salary' : [ '5000' , '6000' , '7000'] , 'department' : ['sales' , 'marketing' , 'operartions' ] }
Create a dictionary where you have to take 3 inputs from the user and take keys from this list. l1=[ 'name' , 'salary' , 'department' ] employee_dict={ 'name' : [ 'john' , 'mike' , 'sara'], 'salary' : [ '5000' , '6000' , '7000'] , 'department' : ['sales' , 'marketing' , 'operartions' ] }
Create a list of 4 dictionaries and each dictionary holds name, roll_no, city, and stream of each student. l1=[ {'name' : 'ajay', 'roll_no': '001', 'city' : 'pune', 'stream':'science' }, {'name' : 'anuj', 'roll_no': '002', 'city' : 'mumbai', 'stream':'commerce' }, {'name' : 'anil', 'roll_no': '003', 'city' : 'agra', 'stream':'arts' }, ]
Dictionary Operations
Create a dictionary called
fruit_dict
with the following key-value pairs: "apple" : 1, "banana" : 2, "orange" : 3. Also print fruit_dict.
Write a program to add a fruit mango in the fruit_dict and print all the fruit names.
Write a program to print the serial order of all the fruits in
fruit_dict.
Write a program to create a dictionary which contains the
fruit name
andtheir prices(float).
Take fruit name and prices from user. Create for 5 fruits.
Write a program to count the frequency of each word in the given sentence: "the quick brown fox jumps over the lazy dog".
Create a dictionary
my_dict
with three key-value pairs: "name" : "John", "age" : 30, "city" : "New York".
Write a program to check if the key "name" is in
my_dict
.Write a program to check if the value "Chicago" is in
my_dict
.Write a program to get the length of
my_dict
.Write a program to clear all the elements in
my_dict
.
Create two dictionaries
dict1
anddict2
with the following key-value pairs: "a" : 1, "b" : 2, "c" : 3 and "c" : 4, "d" : 5, "e" : 6 respectively.
Write a program to merge
dict2
intodict1
.Write a program to create a new dictionary that contains only the key-value pairs that are common in both
dict1
anddict2
.Write a program to remove a key-value pair from
dict1
.
Write a program to sort a dictionary in ascending and descending both. use d = {'oil':230, 'clip':150, 'stud':175, 'Nut':35}
Write a program to check whether the dictionary is empty or not.
Create a dictionary
employee_dict
with the following key-value pairs: "John" : {"salary" : 5000, "department" : "Sales"}, "Mike" : {"salary" : 6000, "department" : "Marketing"}, "Sara" : {"salary" : 7000, "department" : "Operations"}.
Write a program to find the employee with the highest salary in
employee_dict
.Write a program to find the average salary of all employees in
employee_dict
.Write a program to add a new employee to
employee_dict
.Write a program to remove an employee from
employee_dict
.
Suppose you are working in a retail store and you want to keep track of sales by month. Write a program to create a dictionary
sales_dict
that stores the monthly sales data as follows:
Jan
5000
Feb
7000
Mar
4500
Apr
9000
May
6000
Write a program to:
Print the sales in January.
Print the total sales for the first quarter (Jan to Mar).
Print the months in which sales were greater than 6000.
Add the sales data for June (8000) to the dictionary.
Remove the sales data for April from the dictionary.
You have been given the following data about the number of COVID-19 cases in different countries: cases{ "USA": 3500000, "India": 2300000, "Brazil": 1800000, "Russia": 1200000, "France": 800000, "UK": 700000, "Turkey": 650000, "Italy": 600000, "Spain": 550000, "Germany": 500000 } Write a program to find the top 3 countries with the highest number of COVID-19 cases.
You are given a dictionary
sales_data
containing sales information for a company's products. Each key-value pair in the dictionary represents a product's name and its corresponding sales in dollars for the year. sales_data = { 'Product A': 15000, 'Product B': 25000, 'Product C': 30000, 'Product D': 40000, 'Product E': 50000 }Write a program to calculate the total sales for the company.
Write a program to calculate the average sales per product.
Write a program to find the best-selling product.
Last updated