Searching a list of pairs of numbers This works fine but I feel it can be better optimized.

#!/usr/bin/env py

s = "1:5.9,1.5:7,2:10,4:18,8:40"
load_value = raw_input("Enter a load value\n")
li =  s.split(',')
driver = None
for index,item in enumerate(li):
    if load_value == li[index].split(':')[1]:
        driver = li[index].split(':')[0]
        print driver
if not driver:
    print "Could not find driver value"


Output:




Enter a load value
5.9
1
Maybe you can use dict instead of str to store the driver-load values. If the driver is the key, you can search easily.

#!/usr/bin/env py

s = {'5.9':'1', '7':'1.5', '10':'2', '18':'4', '40':'8'}
load_value = raw_input("Enter a load value\n")
driver = s.get(load_value)
if driver is None:
    print "Could not find driver value"
else:
    print driver