I have 2-dimensional list in which each entry has a timestamp (int) and a second value that can be an int, string or object.
I'm using the min() function to get the entry with the lowest timestamp:
a = [[2, "start C"],
[6, 2484],
[15, "finish C"]]
print(min(a))
Output:
[2, 'start C']
When there are identical lowest timestamps min() will compare the second column of those items.
This works only as long as the second column has comparable values:
a = [[2, "start C"],
[2, "start B"],
[15, "finish C"]]
print(min(a))
Output:
[2, 'start B']
If the second column contains different data types it throws an error:
a = [[2, "start C"],
[2, 2484],
[15, "finish C"]]
print(min(a))
Output:
TypeError: '<' not supported between instances of 'int' and 'str'
How can I let only the first column be checked for the minimum? When there are identical timestamps it should simply return the first item encountered.