I have a fixed dictionary which I cannot change and need to find the correct key without knowing the number of whitespace in the keys. Here is what I have:
mydict = dict(
'entry 1'='first',
'entry 2'='second',
# ...
'entry 10'='tenth',
# ...
)
I need to find the correct entry based on the "number", e.g. mydict[entry 4], but without knowing how much whitespace separates the word entry and the number. Any idea how I can achieve this?
I would assume there is some clever regex I can use that allows for an arbitrary amount of characters between entry and the number, but with whitespace as the only allowed character.