Maurice LING wrote:
I'm looking for a way to do this: I need to scan a text (paragraph or
so) and look for occurrences of " ()". That is, if the
text just before the open bracket is the same as the text in the
brackets, then I have to delete the brackets, with the text in it.
How's this?
import
Maurice LING wrote:
> Matt wrote:
> > I'd HIGHLY suggest purchasing the excellent > href="http://www.oreilly.com/catalog/regex2/index.html";>Mastering
> > Regular Expressions by Jeff Friedl. Although it's mostly
geared
> > towards Perl, it will answer all your questions about regular
> > express
Maurice -
Here is a pyparsing treatment of your problem. It is certainly more
verbose, but hopefully easier to follow and later maintain (modifying
valid word characters, for instance). pyparsing implicitly ignores
whitespace, so tabs and newlines within the expression are easily
skipped, withou
Matt wrote:
I'd HIGHLY suggest purchasing the excellent http://www.oreilly.com/catalog/regex2/index.html";>Mastering
Regular Expressions by Jeff Friedl. Although it's mostly geared
towards Perl, it will answer all your questions about regular
expressions. If you're going to work with regexs, this
Maurice LING wrote:
> Matt wrote:
> >
> >
> > Try this:
> > import re
> > my_expr = re.compile(r'(\w+) (\(\1\))')
> > s = "this is (is) a test"
> > print my_expr.sub(r'\1', s)
> > #prints 'this is a test'
> >
> > M@
> >
>
> Thank you Matt. It works out well. The only think that gives it
problem
>
Matt wrote:
Try this:
import re
my_expr = re.compile(r'(\w+) (\(\1\))')
s = "this is (is) a test"
print my_expr.sub(r'\1', s)
#prints 'this is a test'
M@
Thank you Matt. It works out well. The only think that gives it problem
is in events as "there (there)", where between the word and the same
Maurice LING wrote:
> Hi,
>
> I'm looking for a way to do this: I need to scan a text (paragraph or
> so) and look for occurrences of " ()". That is, if
the
> text just before the open bracket is the same as the text in the
> brackets, then I have to delete the brackets, with the text in it.
>
>
Hi,
I'm looking for a way to do this: I need to scan a text (paragraph or
so) and look for occurrences of " ()". That is, if the
text just before the open bracket is the same as the text in the
brackets, then I have to delete the brackets, with the text in it.
Does anyone knows any way to achie
On Fri, 1 Apr 2005 17:33:59 -0800, "Todd_Calhoun" <[EMAIL PROTECTED]> wrote:
>I'm trying to learn about text processing in Python, and I'm trying to
>tackle what should be a simple task.
>
>I have long text files of books with a citation between each paragraph,
Most text files aren't long enough
My apologies you did indeed use writelines correctly ;)
dohhh!
I had a gut reaction to this.
Py>f = ['hij\n','efg\n','abc\n']
Py> for i in f:
... if i.startswith('a'):
... i == ''
Py> f
['hij\n', 'efg\n', 'abc\n']
Notice that it does not modify the list in any way.
You are trying to loo
Strings have many methods that are worth learning.
If you haven't already discovered dir(str) try it.
Also I am not sure if you were just typing in some pseudocode, but your
use of writelines is incorrect.
help(file.writelines)
Help on built-in function writelines:
writelines(...)
writelines(s
Close:
> if line[:4] == 'Bill':
. ^^
> line == ' '
>
--
http://mail.python.org/mailman/listinfo/python-list
I'm trying to learn about text processing in Python, and I'm trying to
tackle what should be a simple task.
I have long text files of books with a citation between each paragraph,
which might be like "Bill D. Smith, History through the Ages, p.5".
So, I need to search for every line that starts
13 matches
Mail list logo