I think simple regex may come handy,
p=re.compile(r'(.+) .*\1')#note the space
s=p.search("python and i love python")
s.groups()
(' python',)
But that matches for only one double word.Someone else could light up here
to extract all the double words.Then they can be removed from the o
On Wed, Nov 4, 2009 at 4:27 AM, Tim Chase wrote:
> kylin wrote:
>
>> I need to remove the word if it appears in the paragraph twice. could
>> some give me some clue or some useful function in the python.
>>
>
> Sounds like homework. To fail your class, use this one:
>
> >>> p = "one two three fou
Can we use inp_paragraph.count(iter_word) to make it simple ?
It would work, but the performance will drop off sharply as the
length of the paragraph grows, and you'd still have to keep track
of which words you already printed so you can correctly print the
first one. So you might as well
On Wed, Nov 4, 2009 at 4:27 AM, Tim Chase wrote:
> kylin wrote:
>
>> I need to remove the word if it appears in the paragraph twice. could
>> some give me some clue or some useful function in the python.
>>
>
> Sounds like homework. To fail your class, use this one:
>
> >>> p = "one two three fou
I need to remove the word if it appears in the paragraph twice. could
some give me some clue or some useful function in the python.
--
http://mail.python.org/mailman/listinfo/python-list
kylin wrote:
I need to remove the word if it appears in the paragraph twice. could
some give me some clue or some useful function in the python.
Sounds like homework. To fail your class, use this one:
>>> p = "one two three four five six seven three four eight"
>>> s = set()
>>> print ' '.joi
On Tue, Nov 3, 2009 at 11:13 PM, kylin wrote:
> I need to remove the word if it appears in the paragraph twice. could
> some give me some clue or some useful function in the python.
Well, it depends a bit on what you call 'the same word' (In the
paragraph "Fly fly, fly!" does the word fly occur 0
kylin wrote:
> I want to remove all the punctuation and no need words form a string
> datasets for experiment.
> I need to remove the word if it appears in the paragraph twice. could
> some give me some clue or some useful function in the python.
>>> para = u"""I need to remove the word if it ap