I have a list of tuples:
lst = [('54', '1.74', '253.2'), ('342', '2.85', '13.46'), ('53','2.43', '15.63')]
I want to find the tuple with item at position [1]
closest to 2.0
I go like this:
number = lst[0][1]
for i in lst:
if abs(float(i[1]) - 2) < float(number):
number = i[1]
if number in i:
print i
But when I'm trying to convert the string to float it raises an exception ;/ How can I actually do this?