471,337 Members | 1,146 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

searching dict key with reqex

hi,

can I use regex instead of a plain string with this kind of syntax ...

'name' in a_dictionary

something like

r'name_\D+' in a_dictionary?

Thanks
james

Aug 21 '07 #1
1 945
james_027 wrote:
hi,

can I use regex instead of a plain string with this kind of syntax ...

'name' in a_dictionary

something like

r'name_\D+' in a_dictionary?

Thanks
james
This makes it a one-liner:

import re

def rgxindict(rgx, adict):
return any(re.match(rgx,k) for k in adict)

James

Aug 21 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Robin Cull | last post: by
6 posts views Thread by rh0dium | last post: by
7 posts views Thread by MTD | last post: by
2 posts views Thread by Gerardo Herzig | last post: by
15 posts views Thread by Gigs_ | last post: by
20 posts views Thread by Seongsu Lee | last post: by
4 posts views Thread by Giampaolo Rodola' | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.