What does this package do? - Episode 2: Enhanced Dictionaries (defaultdict and Counter)

preview_player
Показать описание
In this episode, we take a look at python’s defaultdict function and Counter class in the collections library.

00:00 - Introduction
00:22 - Creating events
01:00 - Console session on defaultdict
02:51 - Categorizing events
05:02 - Debugging defaultdict
06:23 - Introduction to Counter
06:54 - Debug session on Counter
09:35 - Outro
Рекомендации по теме
Комментарии
Автор

Thank you so much for doing this series, Naiful, and to JetBrains for sponsoring it! I consider myself a fairly advanced Python programmer, but there are so many packages I haven't spent enough time with. You crammed a lot of great tips, and even a fix for a common problem, in less than 10 minutes!

Emily_Entropy
Автор

An easy way to remove zero and negative values from the counter is to use the unary + operator. In the case here to cleanup event_frequency, you can just say:
event_frequency = +event_frequency
This avoids having to iterate or create additional variables.

MajorMichael
Автор

Super useful. Cleans up a bit of code that's been annoying me recently.
I wouldn't mind if the code was available.

madst