Simplifying code with defaultdict in python

preview_player
Показать описание
Tips and Tricks 52​ : Simplifying code with defaultdict in python

Simplifying Code with defaultdict

You start with an empty notebook, and you want to add three types of fruits:
apples, bananas, and cherries.

To do this, you open the notebook and look for the page for "apples."
But the notebook is empty, so there's no page for "apples."

You have to create a page for "apples" first and write down that you have 2 apples.

Next, you want to add bananas. You look for the page for "bananas,"
but it's not there, so you create a new page for "bananas" and write down that you have 1 banana.

You repeat this process for cherries, creating a page for them and writing
that you have 3 cherries.

Now, imagine someone asks you, "How many dates do you have?" You try to look for a "dates" page in your notebook, but it doesn't exist.

You have to be careful not to make mistakes and accidentally forget to create a page for any fruit or forget to update the count correctly.
This manual checking and updating make your notebook longer and more error-prone.

The need for defaultdict:

You start with a magical notebook (a defaultdict) that automatically creates a page for any fruit you mention.

You confidently write down the counts of your fruits without worrying if the
pages exist or not. For example, you just say, "I have 2 apples," and the notebook creates an "apples" page for you if it doesn't already exist.

You add bananas and cherries the same way, without needing to manually check or create pages.

Now, when someone asks about dates, you confidently check the "dates" page in your notebook. If it doesn't exist, the notebook kindly tells you that you have 0 dates.

Your magical notebook simplifies your record-keeping. You don't have to write extra code to handle missing pages or worry about making mistakes, making your record-keeping shorter and more accurate.
Рекомендации по теме
Комментарии
Автор

Hey Sreeni, you have always created great videos which have been helpful. Few requests -
1. If you can make a video on Google's semantic segmentation Deep Lab and how to apply custom weight losses to individual classes to counter data imbalance issues.
2. Few videos will be helpful related to ML system designs as well.
3. Custom training on panoptic segmentation models.

umairsabir
Автор

Hello. Good morning, can anyone help me please?
It may not be the correct site, and if so I apologize.
But I'm starting to learn how to program.
I'm using MacBook and I only have both times " ".
Does anyone know how to add single quotes?
After my ESC key there are no single quotes.
Can someone help me please?
Thank you very much

SimaoMoura