RUVIDEO
Поделитесь видео 🙏

Simplifying code with defaultdict in python

Tips and Tricks 52 : Simplifying code with defaultdict in python

Code from this video is available here: https://github.com/bnsreenu/python_for_microscopists/blob/master/tips_tricks_52_Hidden%20Gems%20-%20defaultdict/Tips%20Tricks%2052%20-Hidden%20Gems%20-%20defaultdict.py

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.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Simplifying code with defaultdict in python», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.