From 1d5087d3e0fc3e439c5264c0abc92398da93242e Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 20 Aug 2014 21:50:31 -0700 Subject: [PATCH] TradeDB.list_search will now take a key= parameter so you can use non-trivial enumerables --- tradedb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tradedb.py b/tradedb.py index cd6e9e2e..29868669 100644 --- a/tradedb.py +++ b/tradedb.py @@ -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", @@ -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: