473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

regular expressions as hash keys in python

50
hi, bit of a strange question but does anyone know if there is a way of storing regular expressions as dictionary keys in python?

I ask because i need to match patterns of sequences against other sequences and the patterns themselves are the most important thing. If I could store the patterns in a dictionary, and then cycle through them to see if the patterns are in another sequence, this would be ideal.

thanks
Apr 1 '07 #1
1 1253
ghostdog74
511 Expert 256MB
hi, bit of a strange question but does anyone know if there is a way of storing regular expressions as dictionary keys in python?

I ask because i need to match patterns of sequences against other sequences and the patterns themselves are the most important thing. If I could store the patterns in a dictionary, and then cycle through them to see if the patterns are in another sequence, this would be ideal.

thanks
you can put them values
eg
Expand|Select|Wrap|Line Numbers
  1. >>> d = { "1": "\d+" , '2': "\w+" }
  2. >>> data = open("file").read()
  3. >>> for i, j in d.iteritems():
  4. ...  print re.findall(i,data)
  5. ...
  6. ['1']
  7. ['2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2']
  8.  
Apr 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Erik Lechak | last post by:
Hello all, I wrote the code below. It is simply a dictionary that uses regular expressions to match keys. A quick look at _test() will give you an example. Is there a module that already...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
6
by: pycraze | last post by:
Hi , I am using Fedora Core -3 and my Python version is 2.4 . kernel version - 2.6.9-1.667smp There is some freakish thing that happens with python hashes when i run a python script my...
0
by: kirat.singh | last post by:
Forgive me if this has already been discussed, but it seems to me that one could reduce the memory usage of dictionaries by 2/3 by removing the precomputed hash in each bucket. Since...
19
by: Davy | last post by:
Hi all, I am a C/C++/Perl user and want to switch to Python (I found Python is more similar to C). Does Python support robust regular expression like Perl? And Python and Perl's File...
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
34
by: Antoine De Groote | last post by:
Hello, Can anybody tell me the reason(s) why regular expressions are not built into Python like it is the case with Ruby and I believe Perl? Like for example in the following Ruby code line =...
20
by: Geoff Hill | last post by:
What's the way to go about learning Python's regular expressions? I feel like such an idiot - being so strong in a programming language but knowing nothing about RE.
13
by: Wiseman | last post by:
I'm kind of disappointed with the re regular expressions module. In particular, the lack of support for recursion ( (?R) or (?n) ) is a major drawback to me. There are so many great things that can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.