Search in list of dictionaries

Alex Gusarov amgusarov at
Thu Feb 19 18:17:56 CET 2009

 Hello everybody!

I've a list of dictionaries with 'shorcut' and 'command' keys. When user
types a word program must search this list for a typed shortcut and then run
linked command. What I've wrote:

        for cmd in self.commands:
            if cmd['shortcut'] == input:

But it's a brute-force method and I think there is another way in searching
items through a list by dictionary key. Please give me advice how can I
implement fast search in list of dictionaries by some dictionary key. In my
mind language:

list.get({'shortcut' == input})

Thanks a lot, Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list