On Sep 8, 11:02 am, [EMAIL PROTECTED] wrote:
> Hi;
>
> I'm trying to insert XYZ before a keyword in a string. The first and
> the last occurence of hello in the string t1 (t1="hello world hello.
> hello \nwhy world hello") are keywords. So after the insertion of XYZ
> in this string, the result sho
On Mon, 10 Sep 2007 00:29:50 -0700, Ant wrote:
> On Sep 10, 3:15 am, "a.m." <[EMAIL PROTECTED]> wrote:
>> Thanks guys for you help. I ended up doing this way (for the
>> records)...
>>
>> t1 = "hello world hello. hello. \nwhy world hello"
> ...
>
> Another approach may be to use the re module's s
On Sep 10, 3:15 am, "a.m." <[EMAIL PROTECTED]> wrote:
> Thanks guys for you help. I ended up doing this way (for the
> records)...
>
> t1 = "hello world hello. hello. \nwhy world hello"
...
Another approach may be to use the re module's sub function:
import re
t1 = 'hello world hello. hello. \nw
Thanks guys for you help. I ended up doing this way (for the
records)...
t1 = "hello world hello. hello. \nwhy world hello"
while indexhttp://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] a écrit :
> Hi;
>
> I'm trying to insert XYZ before a keyword in a string.
Then forget about it. Python's strings are immutable.
(snip)
> The python doesn't supports t1[keyword_index]="XYZhello" (string
> object assignment is not supported). How do I get to this problem? Any
>
On 9/8/07, Zentrader <[EMAIL PROTECTED]> wrote:
> Same solution as above, but if you just want "Hello" and to not
> include words containing "Hello", i.e. "Helloing" or "Unhello", then
> you want to include a leading and/or trailing space.
You can also use the re (regular expression) module to sea
Same solution as above, but if you just want "Hello" and to not
include words containing "Hello", i.e. "Helloing" or "Unhello", then
you want to include a leading and/or trailing space.
lit=" hello" ## note added space
t1="nothello world hello. hello \nwhy world hello"
start = t1.find(lit)
t2 = t
On 9/8/07, David <[EMAIL PROTECTED]> wrote:
> > The python doesn't supports t1[keyword_index]="XYZhello" (string
> > object assignment is not supported). How do I get to this problem? Any
> > sugguestions?
>
> Build a new string var using slicing. eg:
>
> t1 = t1[:keyword_index] + "XYZhello" + [key
> The python doesn't supports t1[keyword_index]="XYZhello" (string
> object assignment is not supported). How do I get to this problem? Any
> sugguestions?
Build a new string var using slicing. eg:
t1 = t1[:keyword_index] + "XYZhello" + [keyword_index]
Or use string formatting:
t1 = "your text
Hi;
I'm trying to insert XYZ before a keyword in a string. The first and
the last occurence of hello in the string t1 (t1="hello world hello.
hello \nwhy world hello") are keywords. So after the insertion of XYZ
in this string, the result should be t1 = "XYZhello world hello. hello
\nwhy world XYZ
10 matches
Mail list logo