3 def pfxmatch(pfx, item):
4 return str(item)[:len(pfx)] == pfx
6 def ipfxmatch(pfx, item):
7 return str(item).upper()[:len(pfx)] == pfx.upper()
9 class ambiguous(LookupError):
10 def __init__(self, a, b):
11 super().__init__("ambigous match: %s and %s" % (a, b))
15 def find(seq, *, item=None, test=None, match=None, key=None, default=LookupError):
18 if match is None and item is not None:
19 match = lambda o: test(item, o)
28 if default is LookupError:
29 raise ambiguous(key(found), key(thing))
34 if default is LookupError: