Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use key and itemgetter in python

Shulou Source: shulou.com Published: 2022-06-01 06:12:30 10月04日 Update

This article mainly introduces how to use key and itemgetter in python, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

Built-in functions, keys and itemgetters

As mentioned earlier, try to use built-in functions as much as possible, as follows to sort lists using key, operator.itemgetter:

import operatormy_list = [("Josh", "Grobin", "Singer"),("Marco", "Polo", "General"),("Ada", "Lovelace", "Scientist")]my_list.sort (key=operator.itemgetter(0))my_list Thank you for reading this article carefully. I hope that the article "How to use key and itemgetter in python" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it a lot. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Tags: Articles functions values interests at the same time more friends knowledge editing industry information information channels channels references learning help sorting support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL MariaDB Shulou Technology Shulou Tech Info