Skip to content

Commit

Permalink
TradeDB.list_search will now take a key= parameter so you can use non…
Browse files Browse the repository at this point in the history
…-trivial enumerables
  • Loading branch information
kfsone committed Aug 21, 2014
1 parent 1d14a72 commit 1d5087d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def fetch_all(self, sql):
yield row


def list_search(self, listType, lookup, values):
def list_search(self, listType, lookup, values, key=lambda item: item):
""" Seaches [values] for 'lookup' for least-ambiguous matches,
return the matching value as stored in [values].
If [values] contains "bread", "water", "biscuits and "It",
Expand All @@ -346,7 +346,7 @@ def list_search(self, listType, lookup, values):
match = None
needle = self.normalized_str(lookup)
for val in values:
normVal = self.normalized_str(val)
normVal = self.normalized_str(key(val))
if normVal.find(needle) > -1:
# If this is an exact match, ignore ambiguities.
if normVal == needle:
Expand Down

0 comments on commit 1d5087d

Please sign in to comment.