Searching Python dictionary for matching key -
i want search python dictionary key matches initial sequence of letters. however, it's bit more complicated , lost myself midway in confusion.
example: have string "abstthgihg" , want search dictionary key matches last 9 letters of string. if none found want search dictionary key matches last 8 letters of string.
i have no idea how match specific number of letters (here "the last x letters") key (or how search key) have hopes here can perhaps name function enables me or can up. there no code can present since first thing program does. can specify "the last 9 letters" x = string[1:]
? idea have how specify letters of string use search.
since dictionaries hashed tables, can't them last bit of key whole key. instead have iterate on keys
for key in dictionary.keys(): if key[-9:] == 'bstthgihg': print('i found it!!') break
note use of key[-9:]
Comments
Post a Comment