Set Table List to Near Selected Value

I’m trying to get a table List to position closest to a selected value. The user can type in a partial name of something on the list in a text field, and the list will position to the closest match.

For example, say I ask someone to type a word in a text field. I then want to open a table List populated with an alphabetized list of word and position to the closest word that matches their input. Similar to autocomplete, but with a separate table List that positions to the closest line.

I know I can do this by looking through the underlying dataset I’m using to populate the list and set the index value for the table List, but I was looking for something “built-in”.


the bisect library might help you out.

import bisect

listIn = ['constitute', 'eflux', 'intrigue', 'sedge', 'stem', 'whim']

valueIn = 'intr'

bisectValue = bisect.bisect(listIn, valueIn) 

print 'Nearest value:', listIn[bisectValue]