import re
s1 = I am an american
s2 = I am american an
for s in [s1, s2]:
print re.findall( (am|an) , s)
# Results:
# ['am']
# ['am', 'an']
---
I want the results to be the same for each string. What am I doing
wrong?
--
http://mail.python.org/mailman/listinfo/python-list
According to documentation re.findall takes a compiled pattern as a
first argument. So try
patt = re.compile(r'(am|an)')
re.findall(patt, s1)
re.findall(patt, s2)
2009/4/18 Jesse Aldridge jessealdri...@gmail.com:
import re
s1 = I am an american
s2 = I am american an
for s in [s1, s2]:
On 2009-04-17 16:57, Eugene Perederey wrote:
According to documentation re.findall takes a compiled pattern as a
first argument. So try
patt = re.compile(r'(am|an)')
re.findall(patt, s1)
re.findall(patt, s2)
No, it will take a string pattern, too.
--
Robert Kern
I have come to believe that
On 2009-04-17 16:49, Jesse Aldridge wrote:
import re
s1 = I am an american
s2 = I am american an
for s in [s1, s2]:
print re.findall( (am|an) , s)
# Results:
# ['am']
# ['am', 'an']
---
I want the results to be the same for each string. What am I doing
wrong?
findall() finds
s1 = I am an american
s2 = I am american an
for s in [s1, s2]:
print re.findall( (am|an) , s)
# Results:
# ['am']
# ['am', 'an']
---
I want the results to be the same for each string. What am I doing
wrong?
In your first case, the regexp is consuming the am (four
characters,
On Apr 17, 4:49 pm, Jesse Aldridge jessealdri...@gmail.com wrote:
import re
s1 = I am an american
s2 = I am american an
for s in [s1, s2]:
print re.findall( (am|an) , s)
# Results:
# ['am']
# ['am', 'an']
---
I want the results to be the same for each string. What am I
On Apr 17, 5:28 pm, Paul McGuire pt...@austin.rr.com wrote:
-- Paul
Your find pattern includes (and consumes) a leading AND trailing space
around each word. In the first string I am an american, there is a
leading and trailing space around am, but the trailing space for
am is the leading
On Apr 17, 5:30 pm, Paul McGuire pt...@austin.rr.com wrote:
On Apr 17, 5:28 pm, Paul McGuire pt...@austin.rr.com wrote: -- Paul
Your find pattern includes (and consumes) a leading AND trailing space
around each word. In the first string I am an american, there is a
leading and trailing