[Tutor] How to substitute an element of a list as a pattern for
re.compile()
kumar s
ps_python at yahoo.com
Thu Dec 30 02:01:23 CET 2004
Hi Group:
I have Question:
How can I substitute an object as a pattern in making
a pattern.
>>> x = 30
>>> pattern = re.compile(x)
My situation:
I have a list of numbers that I have to match in
another list and write them to a new file:
List 1: range_cors
>>> range_cors[1:5]
['161:378', '334:3', '334:4', '65:436']
List 2: seq
>>> seq[0:2]
['>probe:HG-U133A_2:1007_s_at:416:177;
Interrogation_Position=3330; Antisense;',
'CACCCAGCTGGTCCTGTGGATGGGA']
A slow method:
>>> sequences = []
>>> for elem1 in range_cors:
for index,elem2 in enumerate(seq):
if elem1 in elem2:
sequences.append(elem2)
sequences.append(seq[index+1])
This process is very slow and it is taking a lot of
time. I am not happy.
A faster method (probably):
>>> for i in range(len(range_cors)):
for index,m in enumerate(seq):
pat = re.compile(i)
if re.search(pat,seq[m]):
p.append(seq[m])
p.append(seq[index+1])
I am getting errors, because I am trying to create an
element as a pattern in re.compile().
Questions:
1. Is it possible to do this. If so, how can I do
this.
Can any one help correcting my piece of code and
suggesting where I went wrong.
Thank you in advance.
-K
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Tutor
mailing list