Search code examples
pythonlistminplaying-cards

Python, min among first objects in lists


I have a very particular problem, I have a deck of cards. The deck is a list of lists of tuples, each internal list is a suit with card tuples (suit, value), sorted smallest to largest(2-Ace). I would like to find the smallest card in the deck. So basically I want to take the first object from each suit, and find the smallest. Short of an horridly ugly for loop, what is the most pythonic way to do this?


Solution

  • min takes a key function. You can use this to get the first element to use it as the comparison:

    min(my_list, key=lambda x: x[0])