Telegram Group & Telegram Channel
Чтобы отсортировать словарь по его значениям, используйте функцию sorted с пользовательской функцией ключа:


>>> d = dict(a=1, c=3, b=2)
>>> sorted(d.items(), key=lambda item: item[1])
[('a', 1), ('b', 2), ('c', 3)]


Однако такая функция уже существует в модуле operator:


>>> from operator import itemgetter
>>> sorted(d.items(), key=itemgetter(1))
[('a', 1), ('b', 2), ('c', 3)]


Вы также можете сортировать только ключи вместо пар ключ-значение:


>>> sorted(d, key=lambda k: d[k])
['a', 'b', 'c']


И снова, эту лямбду можно заменить уже существующим методом:


>>> sorted(d, key=d.get)
['a', 'b', 'c']


👉@BookPython



tg-me.com/BookPython/3632
Create:
Last Update:

Чтобы отсортировать словарь по его значениям, используйте функцию sorted с пользовательской функцией ключа:


>>> d = dict(a=1, c=3, b=2)
>>> sorted(d.items(), key=lambda item: item[1])
[('a', 1), ('b', 2), ('c', 3)]


Однако такая функция уже существует в модуле operator:


>>> from operator import itemgetter
>>> sorted(d.items(), key=itemgetter(1))
[('a', 1), ('b', 2), ('c', 3)]


Вы также можете сортировать только ключи вместо пар ключ-значение:


>>> sorted(d, key=lambda k: d[k])
['a', 'b', 'c']


И снова, эту лямбду можно заменить уже существующим методом:


>>> sorted(d, key=d.get)
['a', 'b', 'c']


👉@BookPython

BY Библиотека Python разработчика | Книги по питону


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/BookPython/3632

View MORE
Open in Telegram


Библиотека Python разработчика Telegram | DID YOU KNOW?

Date: |

Start with a fresh view of investing strategy. The combination of risks and fads this quarter looks to be topping. That means the future is ready to move in.Likely, there will not be a wholesale shift. Company actions will aim to benefit from economic growth, inflationary pressures and a return of market-determined interest rates. In turn, all of that should drive the stock market and investment returns higher.

In many cases, the content resembled that of the marketplaces found on the dark web, a group of hidden websites that are popular among hackers and accessed using specific anonymising software.“We have recently been witnessing a 100 per cent-plus rise in Telegram usage by cybercriminals,” said Tal Samra, cyber threat analyst at Cyberint.The rise in nefarious activity comes as users flocked to the encrypted chat app earlier this year after changes to the privacy policy of Facebook-owned rival WhatsApp prompted many to seek out alternatives.Библиотека Python разработчика from us


Telegram Библиотека Python разработчика | Книги по питону
FROM USA