Python: split and select the best one for undefined number of entries -


sorry if question silly... looking trick in python allow splitting line , selecting best value , corresponding source, actual number of entries unknown, can 1 100.

x = "32.1 (pdbbind), 50.1 (bdb), 83.0 (bmoad_4832)" in x.split(","):     b = []     if float(i.split()[0]) < float(b[0]):         b = i.split()[0] 

i error "list index out of range".

the problem here:

b = [] if float(i.split()[0]) < float(b[0]):                               #^ b empty list, b[0] raise error 

if understand problem right, concise solution be:

>>> max(x.split(","), key=lambda x: float(x.split()[0])) ' 83.0 (bmoad_4832)' 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -