Python Dictionary Comprehensions

preview_player
Показать описание
Comprehensions are a powerful tool in Python that allow you to create new lists, sets and dictionaries, populated with values. This video explains how Dict comprehensions work through 10 code examples that include using lists, range function, and existing dicts, as well as if-else conditions and other variations.
#python
Рекомендации по теме
Комментарии
Автор

Helpful. I used this to calculate the center of mass for (xi, yi) objects.

fizixx
Автор

Awesome video Joe, thank you! A few things to note though:
- dictionaries in Python ARE ordered. They have been since Python 3.6, and order has been guaranteed since 3.7 :))
- Example 4 is convoluted and impractical. Can simply do: dict4 = dict(zip(x, y))

TheMako