How to use key and itemgetter in python
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!