Python: getting the smallest number in a list of tuples

My current plan is to determine which first entry in the Tkinter list is highlighted with .curselection()and combines all the resulting tuples into a list, creating this:

tupleList = [(), (), ('24', '25', '26', '27'), (), (), (), ()]

I am wondering how to determine the smallest integer. Usage .min(tupleList)returns only (), being the lowest entry in the list, but I'm looking for a method that returns 24.

What is the right way to get the smallest integer in any tuple in a list?

+3
source share
3 answers
>>> nums = [(), (), ('24', '25', '26', '27'), (), (), (), ()]
>>> min(int(j) for i in nums for j in i)
24
+6
source
>>> from itertools import chain
>>> nums = [(), (), ('24', '25', '26', '27'), (), (), (), ()]
>>> min(map(int,chain.from_iterable(nums)))
24
+6
source
>>> min(reduce(lambda x, y: x + y, nums))
0
source

All Articles