Python Forum
Partial key lookup in dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Partial key lookup in dictionary
#1
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
Reply
#2
You can try
keys = fnmatch.filter(mydict, "Que*")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  partial functions before knowing the values mikisDeWitte 4 536 Dec-24-2023, 10:00 AM
Last Post: perfringo
  Move Files based on partial Match mohamedsalih12 2 745 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Partial KEY search in dict klatlap 6 1,200 Mar-28-2023, 07:24 AM
Last Post: buran
  remove partial duplicates from csv ledgreve 0 746 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  Webhook, post_data, GPIO partial changes DigitalID 2 953 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  Optimal way to search partial correspondence in a large dict genny92c 0 975 Apr-22-2022, 10:20 AM
Last Post: genny92c
  2-dataframe, datetime lookup problem Mark17 0 1,215 Jan-27-2022, 01:02 AM
Last Post: Mark17
  Python VLookup? Lookup Table? Nu2Python 3 2,373 Oct-25-2021, 08:47 PM
Last Post: Nu2Python
  Partial Matching Rows In Pandas DataFrame Query eddywinch82 1 2,338 Jul-08-2021, 06:32 PM
Last Post: eddywinch82
  Can I replace IF statements with a key lookup ? jehoshua 3 2,461 Mar-05-2021, 10:24 PM
Last Post: jehoshua

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020