Python Forum

Full Version: Partial key lookup in dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Anyone ever needed to do a partial key lookup in a dictionary?
By this for example I mean:

starting_key = myDict.getLike("Que*")
while starting_key is not None:
    print(myDict[starting_key])
    starting_key = starting_key.next()
then iterate from any keys matching the "Que*" until there are no more matches. A bit like the following SQL query that uses a wildcard lookup:

SELECT *
FROM EMPLOYEES E
WHERE E.NAME LIKE "DAR%"
/

Any suggestions as to how to achieve this efficiently?


Thanks

Gary
You can try
keys = fnmatch.filter(mydict, "Que*")