Practicing Dictionary basics with Fruits data
Practicing Dictionary basics with Fruits data Data Science Project
Python Collections

Practicing Dictionary basics with Fruits data

The objective of this project is to practice Python Dictionaries including creating, accessing, modifying, and removing key-value pairs in dictionaries. The project also includes looping through dictionaries and nesting dictionaries. We will use the data containing a nested dictionary of fruits data.
Start this project
Practicing Dictionary basics with Fruits dataPracticing Dictionary basics with Fruits data
Project Created by

Anurag Verma

Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Create a fruits dictionary

Given a variable fruits_data containing information about fruits, your task is to create a dictionary called fruits that mirrors the data in fruits_data. The resulting fruits dictionary should have the following structure:

{
    'apple': {'color': 'red', 'price': 0.99},
    'banana': {'color': 'yellow', 'price': 0.59},
    # Add more fruits here
}

Use the information in fruits_data to populate the fruits dictionary.

codevalidated

Create a Dictionary of Colors and Fruits

Building upon the previous activity where we created a dictionary named fruits, your next task is to create a new dictionary called colors. The colors dictionary should retain the same data as fruits, but with a different structure. In the colors dictionary, the keys should represent the colors of the fruits, and the values should be lists containing the names of fruits of that color.

Upon completion, the colors dictionary should resemble the following structure:

{
    'red': ['apple', 'cherry', 'strawberry', 'raspberry'],
    'yellow': ['banana', 'lemon'],
    # Add more colors and associated fruits here
}

Utilize the information from the fruits dictionary to construct the colors dictionary.

codevalidated

Expand the Fruits Dictionary

Your objective is to augment the existing fruits dictionary by adding the following fruits and their associated information:

('cherry', 'red', 1.99)
('lemon', 'yellow', 0.79)
('lime', 'green', 0.69)

Incorporate this new data into the fruits dictionary.

input

Count the Colors in the 'fruits' Dictionary

Determine the total number of unique colors present in the fruits dictionary. Please submit your answer in the input field below.

Enter your answer as an integer.

input

Determine the Color of 'Mango' in the 'fruits' Dictionary

Find and report the color of the 'mango' fruit in the fruits dictionary. Please enter your answer in the input field below.

Enter your answer as a string. Example: red

input

Quantify the Count of Red Fruits in the 'fruits' Dictionary

Calculate and provide the total count of fruits with the color red in the fruits dictionary. Please input your answer into the designated field below.

Enter your answer as an integer.

input

Calculate the Average Price of All Fruits

Determine the average price of all the fruits within the fruits dictionary. Please input your answer in the designated field below.

Enter your answer as a float. Example: 1.99 (rounded to 2 decimal places)

codevalidated

Develop a Function to Identify Expensive Fruits

Your task is to create a Python function named find_expensive_fruits that accepts two parameters: a dictionary of fruits and a threshold price. The function should return a set of fruit names that have a price exceeding the specified threshold.

Here's how the function definition should appear:

def find_expensive_fruits(fruits_data, threshold_price):
    # Your code goes here

The function should output a set of strings.

input

Determine the Average Caloric Value of Fruits

Your objective is to compute the average caloric value of all fruits listed in the fruits dictionary. Please submit your answer in the input field provided.

Enter your answer as a float. Example: 1.99 (rounded to 2 decimal places)

codevalidated

Locate Fruits with 'Excellent' Vitamin C Content

Your task is to identify and compile a list of fruits with "excellent" vitamin C content. This list should be stored in a variable named excellent_vitamin_c_fruits.

For reference, the result should be in the format of a list, such as: ['apple', 'orange', 'kiwi'].

codevalidated

Create a Function to Modify Fruit Prices

Your task is to construct a Python function named update_fruit_price that requires three parameters: the fruits dictionary, the name of the fruit, and the new price. This function should adjust the price of the specified fruit within the dictionary and return the updated dictionary.

Here's how the function definition should appear:

def update_fruit_price(fruits_data, fruit_name, new_price):
    # Your code goes here

The function should return a dictionary.

codevalidated

Compile a List of Fruits with 'low' Sugar Content

Your objective is to generate a list of fruits with "low" sugar content and store this list in a variable named low_sugar_fruits.

For reference, the result should be in the format of a list, like this: ['apple', 'orange', 'kiwi'].

input

Identify the Fruit with the Highest Caloric Content

Your task is to determine and report the fruit with the highest caloric content. Please enter the name of the fruit in the input field provided.

Enter the name of the fruit as a string. Example: apple

codevalidated

Remove 'Banana' from the 'fruits' Dictionary

Your task is to eliminate the entry for 'banana' from the fruits dictionary and then update the fruits dictionary accordingly.

You have to remove the key-value pair for 'banana' from the fruits dictionary.

codevalidated

Generate a Duplicate of the 'fruits' Dictionary

Your goal is to produce a copy of the fruits dictionary and store this copy in a variable named fruits_copy.

codevalidated

Empty the 'fruits' Dictionary

Your task is to clear or empty the fruits dictionary.

Practicing Dictionary basics with Fruits dataPracticing Dictionary basics with Fruits data
Project Created by

Anurag Verma

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

This project is part of

Python Collections

Explore other projects