Steve D'Aprano wrote:
> On Sat, 2 Sep 2017 03:13 am, Ganesh Pal wrote:
>
>> Example :
>>
>> "a" and "1" => a0001
>>
>> "a" and "aa" => c00aa
>
> Why does the leading 'a' change to a 'c'? Is that a mistake? I'll assume
> its a typo.
>
> You want string slicing.
>
> base = 'a'
MRAB , Thanks for your solution it looks neat and best !
On Fri, Sep 1, 2017 at 11:14 PM, MRAB wrote:
> On 2017-09-01 18:13, Ganesh Pal wrote:
>
>> In the fixed length string i.e "a",last 4 bits i.e "" should be
>> replaced by the user provided value ( the value is between 0001 + f f f
On Sat, 2 Sep 2017 03:13 am, Ganesh Pal wrote:
> Example :
>
> "a" and "1" => a0001
>
> "a" and "aa" => c00aa
Why does the leading 'a' change to a 'c'? Is that a mistake? I'll assume its a
typo.
You want string slicing.
base = 'a'
extra = 'ab'
print( base[:-len(extra)] + extra
>Note you should think VERY CAREFULLY about any user input like this. What
are you going to do the user gives you too many digits, too few digits,
non-digits
Thanks the solution i.e using zfill() looks simple :) , we have a check
that will take care of user input than's for noticing that
On Fri,
> (I assume that in your example "a" and "aa" => c00aa, that really
should have been a00aa)
Yes , thanks for noticing.
On Fri, Sep 1, 2017 at 11:18 PM, Irv Kalb wrote:
>
> > On Sep 1, 2017, at 10:13 AM, Ganesh Pal wrote:
> >
> > In the fixed length string i.e "a",last 4 bits i.e "00
> On Sep 1, 2017, at 10:13 AM, Ganesh Pal wrote:
>
> In the fixed length string i.e "a",last 4 bits i.e "" should be
> replaced by the user provided value ( the value is between 0001 + f f f f )
> . I intend to form final_string using a fixed_string and an user provided
> user_string
>
On 01/09/17 18:13, Ganesh Pal wrote:
"a" + "1"===> expected was a0001
'a1'
Why would you expect that? Concatenation means "joining together", so
>>> "foo" + "bar"
'foobar'
No other mangling of either of your original strings is going to happen;
there is no magic going on here.
On 2017-09-01 18:13, Ganesh Pal wrote:
In the fixed length string i.e "a",last 4 bits i.e "" should be
replaced by the user provided value ( the value is between 0001 + f f f f )
. I intend to form final_string using a fixed_string and an user provided
user_string
Example:
fixed_st
In the fixed length string i.e "a",last 4 bits i.e "" should be
replaced by the user provided value ( the value is between 0001 + f f f f )
. I intend to form final_string using a fixed_string and an user provided
user_string
Example:
fixed_string = "a"
user_string ='1'
final str
Fixed full details here http://bugs.python.org/issue16061
--
If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.
Mark Lawrence
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Feb 5, 2009 at 5:59 PM, wrote:
> "S.Selvam Siva" wrote:
> > I tried to do a string replace as follows,
> >
> > >>> s="hi & people"
> > >>> s.replace("&","\&")
> > 'hi \\& peo
"S.Selvam Siva" wrote:
> I tried to do a string replace as follows,
>
> >>> s="hi & people"
> >>> s.replace("&","\&")
> 'hi \\& people'
> >>>
>
> but i was expecting 'hi \&a
On Thu, Feb 5, 2009 at 3:40 AM, S.Selvam Siva wrote:
> Hi all,
>
> I tried to do a string replace as follows,
>
>>>> s="hi & people"
>>>> s.replace("&","\&")
> 'hi \\& people'
>>>>
>
&
Hi all,
I tried to do a string replace as follows,
>>> s="hi & people"
>>> s.replace("&","\&")
'hi \\& people'
>>>
but i was expecting 'hi \& people'.I dont know ,what is something different
here with escape sequence.
--
Yours,
S.Selvam
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 11, 8:55 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of cesco
> > Sent: Wednesday, January 09, 2008 5:34 AM
> > To: [EMAIL PROT
On Jan 12, 2:55 am, Pablo Ziliani <[EMAIL PROTECTED]> wrote:
> * die, thread!
:-)
def altrep7(s):
from itertools import cycle
import re
a = cycle(':,')
return re.sub('_', lambda x: a.next(), s)
altrep7.author="George Sakkis(&Paul Rubin)"
Gives:
## Program by: George Sakkis(&Paul Rubi
Paul Rubin wrote:
> George Sakkis <[EMAIL PROTECTED]> writes:
>
>> from itertools import chain, izip, cycle
>> print ''.join(chain(*izip(s1.split('_'),cycle(':,'[:-1]
>>
>
> from itertools import cycle
> a = cycle(':,')
> print re.sub('_', lambda x: a.next(), s1)
>
Lovely.
If there
On Fri, 11 Jan 2008 14:55:18 -0600, Reedick, Andrew wrote:
> For those of us who still think in Perl, here's an easy to read
...
> s = re.sub(r'_(.*?(_|$))', r':\1', s)
"Easy to read"? Oh that's priceless. Andrew, you should consider writing
comedy professionally!
--
Steven
--
http://mail.
George Sakkis <[EMAIL PROTECTED]> writes:
> from itertools import chain, izip, cycle
> print ''.join(chain(*izip(s1.split('_'),cycle(':,'[:-1]
from itertools import cycle
a = cycle(':,')
print re.sub('_', lambda x: a.next(), s1)
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 9, 6:34 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> cesco <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > say I have a string like the following:
> > s1 = 'hi_cat_bye_dog'
> > and I want to replace the even '_' with ':' and the odd '_' with ','
> > so that I get a new string like the following:
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of cesco
> Sent: Wednesday, January 09, 2008 5:34 AM
> To: python-list@python.org
> Subject: alternating string replace
>
> Hi,
>
> say I have a string like the fol
On Jan 11, 9:54 am, Chris <[EMAIL PROTECTED]> wrote:
> On Jan 9, 12:34 pm, cesco <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > say I have a string like the following:
> > s1 = 'hi_cat_bye_dog'
> > and I want to replace the even '_' with ':' and the odd '_' with ','
> > so that I get a new string like
On Jan 11, 9:31 am, [EMAIL PROTECTED] wrote:
> evenOrOdd = True
> s1, s2 = "hi_cat_bye_dog_foo_bar_red", ""
>
> for i in s1:
>if i == '_':
>s2 += ':' if evenOrOdd else ','
>evenOrOdd = not evenOrOdd
>else:
>s2 += i
>
> print s2
>
> Presently I cannot work out how to
Dennis Lee Bieber:
> So� in Python, your str[n] :=
> ':' just can not be done! You would have to create a new string
> containing everything in front of n, the ':', and then everything behind
> n (skipping n itself, of course). This is a painfully slow operation in
> Python as it allocates memory f
On Jan 9, 12:34 pm, cesco <[EMAIL PROTECTED]> wrote:
> Hi,
>
> say I have a string like the following:
> s1 = 'hi_cat_bye_dog'
> and I want to replace the even '_' with ':' and the odd '_' with ','
> so that I get a new string like the following:
> s2 = 'hi:cat,bye:dog'
> Is there a common recipe t
evenOrOdd = True
s1, s2 = "hi_cat_bye_dog_foo_bar_red", ""
for i in s1:
if i == '_':
s2 += ':' if evenOrOdd else ','
evenOrOdd = not evenOrOdd
else:
s2 += i
print s2
Presently I cannot work out how to use .join instead of += ...
While I realise this is producing a new
On Jan 10, 3:46 am, [EMAIL PROTECTED] wrote:
> Gordon C:
>
> > This is very cool stuff but I suspect that the code is unreadable
> > to many readers, including me. Just for fun here is a complete program,
> > written in Turbo Pascal, circa 1982, that does the job. Readable
> > n'est pas?
>
> I thi
Gordon C:
> This is very cool stuff but I suspect that the code is unreadable
> to many readers, including me. Just for fun here is a complete program,
> written in Turbo Pascal, circa 1982, that does the job. Readable
> n'est pas?
I think it's quite readable, especially if you indent it more
cor
This is very cool stuff but I suspect that the code is unreadable to many
readers, including me. Just for fun here is a complete program, written in
Turbo Pascal, circa 1982, that does the job. Readable n'est pas?
Program dash;
var str: string[80];
n: integer;
odd: boolean;
begin
On Jan 9, 9:39 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Paddy wrote:
> > To see how they act against 'corner cases' and
> > an exercise for me in trying to create corner cases. (I'm in to
> > functional testing at the mo').
>
> sounds more like "pulling requirements out of thin air". not sur
On Jan 9, 9:29 pm, Paddy <[EMAIL PROTECTED]> wrote:
> On Jan 9, 8:56 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> > Donald 'Paddy' McCarthy wrote:
> > > I created some more test strings and ran posters solutions against them.
>
> > the point being?
>
> >
>
> To see how they act against 'corner
Paddy wrote:
> To see how they act against 'corner cases' and
> an exercise for me in trying to create corner cases. (I'm in to
> functional testing at the mo').
sounds more like "pulling requirements out of thin air". not sure that
helps the OP get a better understanding of Python, really.
On Jan 9, 8:56 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Donald 'Paddy' McCarthy wrote:
> > I created some more test strings and ran posters solutions against them.
>
> the point being?
>
>
To see how they act against 'corner cases' and
an exercise for me in trying to create corner cases. (I
On Jan 9, 8:47 pm, [EMAIL PROTECTED] wrote:
> Donald 'Paddy' McCarthy:
>
> [... lots and lots and lots of tests...]
>
> C'mon Paddy, where are the timings too? Are you becoming lazy
> lately? ;-)
>
> Bear bugs,
> bearophile
Get it right before you get it fast. But what is 'right'.
--
http://mail.
Donald 'Paddy' McCarthy wrote:
> I created some more test strings and ran posters solutions against them.
the point being?
--
http://mail.python.org/mailman/listinfo/python-list
Donald 'Paddy' McCarthy:
[... lots and lots and lots of tests...]
C'mon Paddy, where are the timings too? Are you becoming lazy
lately? ;-)
Bear bugs,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 9, 7:41 am, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> On Jan 9, 2008 5:34 AM, cesco <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > say I have a string like the following:
> > s1 = 'hi_cat_bye_dog'
> > and I want to replace the even '_' with ':' and the odd '_' with ','
> > so that I get a new
cesco wrote:
I created some more test strings and ran posters solutions against them.
results attached.
- Paddy.
# alternating_replacements.py
tests = " 1 2_ 3_4 5_6_ 7_8_9 10_11_12_ 13_14_15_16 17_18_19_20_" \
" _ _21 _22_ _23_24 _25_26_ _27_28_29 _30_31_32_ _33_34_35_36" \
" __ _
cesco wrote:
> Hi,
>
> say I have a string like the following:
> s1 = 'hi_cat_bye_dog'
> and I want to replace the even '_' with ':' and the odd '_' with ','
> so that I get a new string like the following:
> s2 = 'hi:cat,bye:dog'
> Is there a common recipe to accomplish that? I can't come up with
On Jan 9, 2008 5:34 AM, cesco <[EMAIL PROTECTED]> wrote:
> Hi,
>
> say I have a string like the following:
> s1 = 'hi_cat_bye_dog'
> and I want to replace the even '_' with ':' and the odd '_' with ','
> so that I get a new string like the following:
> s2 = 'hi:cat,bye:dog'
> Is there a common reci
On Jan 9, 2008 5:34 AM, cesco <[EMAIL PROTECTED]> wrote:
> Hi,
>
> say I have a string like the following:
> s1 = 'hi_cat_bye_dog'
> and I want to replace the even '_' with ':' and the odd '_' with ','
> so that I get a new string like the following:
> s2 = 'hi:cat,bye:dog'
> Is there a common reci
Designed a pretty basic way that is "acceptable" on small strings.
evenOrOdd = True
s1 = "hi_cat_bye_dog_foo_bar_red"
s2 = ""
for i in s1:
if i == '_':
if evenOrOdd:
s2 += ':'
evenOrOdd = not evenOrOdd
else:
s2 += ','
evenOrOdd
My version, uses a re.sub, plus a function used as an object with a
one bit state:
from re import sub
def repl(o):
repl.n = not repl.n
return ":" if repl.n else ","
repl.n = False
print sub("_", repl, "hi_cat_bye_dog_foo_bar_red")
Bye,
bearophile
--
http://mail.python.org/mailman/listi
cesco <[EMAIL PROTECTED]> wrote:
> Hi,
>
> say I have a string like the following:
> s1 = 'hi_cat_bye_dog'
> and I want to replace the even '_' with ':' and the odd '_' with ','
> so that I get a new string like the following:
> s2 = 'hi:cat,bye:dog'
> Is there a common recipe to accomplish that?
cesco wrote:
> say I have a string like the following: s1 = 'hi_cat_bye_dog'
> and I want to replace the even '_' with ':' and the odd '_' with ',' so
> that I get a new string like the following: s2 = 'hi:cat,bye:dog'
>>> import re
>>> from itertools import cycle
>>> re.sub("_", lambda m, c=cycl
On Jan 9, 11:34 am, cesco <[EMAIL PROTECTED]> wrote:
> Hi,
>
> say I have a string like the following:
> s1 = 'hi_cat_bye_dog'
> and I want to replace the even '_' with ':' and the odd '_' with ','
> so that I get a new string like the following:
> s2 = 'hi:cat,bye:dog'
> Is there a common recipe t
cesco wrote:
> and I want to replace the even '_' with ':' and the odd '_' with ','
> so that I get a new string like the following:
> s2 = 'hi:cat,bye:dog'
> Is there a common recipe to accomplish that? I can't come up with any
> solution...
how about splitting on "_", joining pairs with ":", an
Hi,
say I have a string like the following:
s1 = 'hi_cat_bye_dog'
and I want to replace the even '_' with ':' and the odd '_' with ','
so that I get a new string like the following:
s2 = 'hi:cat,bye:dog'
Is there a common recipe to accomplish that? I can't come up with any
solution...
Thanks in a
En Tue, 18 Sep 2007 08:44:32 -0300, <[EMAIL PROTECTED]>
escribi�:
> Hello,
>
> I am trying to replace some string with list objects:
>
my_text1="function1 function2"
from my_module_with_functions_1 import *
from my_module_with_functions_2 import *
>
> # functions in module " my_mo
Hello,
I am trying to replace some string with list objects:
>>> my_text1="function1 function2"
>>> from my_module_with_functions_1 import *
>>> from my_module_with_functions_2 import *
# functions in module " my_module_with_functions_1 ":
my_func1 it's value "function1"
my_func2 it's valu
On 2007-02-06, Robert Kern <[EMAIL PROTECTED]> wrote:
> John Nagle wrote:
>> File "D:\projects\sitetruth\InfoSitePage.py", line 285, in httpfetch
>> sitetext = sitetext.encode('ascii','replace') # force to clean ASCII
>>
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in
>> pos
John Nagle wrote:
> I'm trying to clean up a bad ASCII string, one read from a
> web page that is supposedly in the ASCII character set but has some
> characters above 127. And I get this:
>
> File "D:\projects\sitetruth\InfoSitePage.py", line 285, in httpfetch
> sitetext = sitetext.en
I'm trying to clean up a bad ASCII string, one read from a
web page that is supposedly in the ASCII character set but has some
characters above 127. And I get this:
File "D:\projects\sitetruth\InfoSitePage.py", line 285, in httpfetch
sitetext = sitetext.encode('ascii','replace') # for
Michael Yanowitz schrieb:
> Yeah, I am operating this on a Python script. However, I am working off
> a requirement that the script be pre-processed and the strings replaced
> before executing the script and that if there are any remaining (not
> replaced)
> names that I don't execute the script
> I have been using the string.replace(from_string, to_string, len(string))
> to replace names in a file with their IP address.
> For example, I have definitions file, that looks something like:
> 10.1.3.4 LANDING_GEAR
> 20.11.222.4 ALTIMETER_100
> 172.18.50.138 SIB
> 172.18.50.138 LAPTOP
>
>Michael Yanowitz wrote:
>> Hello:
>>
>> I am hoping someone knows if there is an easier way to do this or
someone
>> already implemented something that does this, rather than reinventing the
>> wheel:
>> I have been using the string.replace(from_string, to_string,
len(string))
>> to replace na
Michael Yanowitz wrote:
> Hello:
>
> I am hoping someone knows if there is an easier way to do this or someone
> already implemented something that does this, rather than reinventing the
> wheel:
> I have been using the string.replace(from_string, to_string, len(string))
> to replace names in a
Hello:
I am hoping someone knows if there is an easier way to do this or someone
already implemented something that does this, rather than reinventing the
wheel:
I have been using the string.replace(from_string, to_string, len(string))
to replace names in a file with their IP address.
For ex
[EMAIL PROTECTED] wrote:
> Check out the .translate method and the string.maketrans documentation.
> You can use it to delete a list of characters all in one line:
>
Yes. This is, more or less, what I were looking for.
P.s. Sure, if replace could accept a tuple... :)
Thanks to all,
Michele
--
Check out the .translate method and the string.maketrans documentation.
You can use it to delete a list of characters all in one line:
>>> s = "I am the walrus"
>>> import string
>>> s.translate(string.maketrans("",""),"aeiou")
'I m th wlrs'
Michele Petrazzo wrote:
> Hi,
> a lot of times I nee
In article <[EMAIL PROTECTED]>,
Michele Petrazzo <[EMAIL PROTECTED]> wrote:
>Hi,
>a lot of times I need to replace more than one char into a string, so I
>have to do something like
>
>value = "test"
>chars = "e"
>for c in chars:
> value = value.replace(c, "")
>
>A solution could be that "replace
> a lot of times I need to replace more than one char into a
> string, so I have to do something like
>
> value = "test"
> chars = "e"
> for c in chars:
>value = value.replace(c, "")
>
> A solution could be that "replace" accept a tuple/list of
> chars, like that was add into the new 2.5 for
> A solution could be that "replace" accept a tuple/list of chars, like
> that was add into the new 2.5 for startswith.
>
> I don't know, but can be this feature included into a future python
> release?
I don't know, but I think it would be useful
as for now I use this
>>> import re
>>> cha
half Of Michele Petrazzo
Sent: Friday, June 30, 2006 4:03 PM
To: python-list@python.org
Subject: string replace
Hi,
a lot of times I need to replace more than one char into a string, so I
have to do something like
value = "test"
chars = "e"
for c in chars:
value = value.replace
Hi,
a lot of times I need to replace more than one char into a string, so I
have to do something like
value = "test"
chars = "e"
for c in chars:
value = value.replace(c, "")
A solution could be that "replace" accept a tuple/list of chars, like
that was add into the new 2.5 for startswith.
I d
Diez B. Roggisch wrote:
> [EMAIL PROTECTED] wrote:
> > I have a config file with the following contents:
> > service A = {
> > params {
> > dir = "c:\test",
> > username = "test",
> > password = "test"
> > }
> > }
> >
> > I want to find username and replace the value with another v
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Fri, 28 Oct 2005 12:27:36 -0700, [EMAIL PROTECTED] wrote:
>
> > hm...Is there a way to get rid of the newline in "print"?
>
> Yes, by using another language *wink*
Ending the print statement with a comma also works;-)
> Or, instead of using pri
Mike Meyer <[EMAIL PROTECTED]> wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
>
> > So how to overwrite the config file directly in script.py instead of
> > running script.py with two params?
>
> Don't overwrite the file directly. Save a copy, then rename it. That
See module fileinput
On Fri, 28 Oct 2005 12:27:36 -0700, [EMAIL PROTECTED] wrote:
> hm...Is there a way to get rid of the newline in "print"?
Yes, by using another language *wink*
Or, instead of using print, use sys.stdout.write().
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Got it, thanks all!
--
http://mail.python.org/mailman/listinfo/python-list
hm...Is there a way to get rid of the newline in "print"?
--
http://mail.python.org/mailman/listinfo/python-list
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> Now it works:
> rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)')
> for line in fileinput.input(FILE, inplace=1):
> m = rex.match(line)
> if m is not None:
> line = "%s%s%s\n" % (m.group(1), new_name, m.group(3))
> pr
[EMAIL PROTECTED] wrote:
> Now it works:
> rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)')
> for line in fileinput.input(FILE, inplace=1):
> m = rex.match(line)
> if m is not None:
> line = "%s%s%s\n" % (m.group(1), new_name, m.group(3))
> print line
>
> But there
Now it works:
rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)')
for line in fileinput.input(FILE, inplace=1):
m = rex.match(line)
if m is not None:
line = "%s%s%s\n" % (m.group(1), new_name, m.group(3))
print line
But there is an extra line break after each line in F
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> So how to overwrite the config file directly in script.py instead of
> running script.py with two params?
Don't overwrite the file directly. Save a copy, then rename it. That
way, you don't replace the new version until you know the old version
is
So how to overwrite the config file directly in script.py instead of
running script.py with two params?
A XML file or ConfigParser is appealing but this is part of a legacy
system...:(
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> I have a config file with the following contents:
> service A = {
> params {
> dir = "c:\test",
> username = "test",
> password = "test"
> }
> }
>
> I want to find username and replace the value with another value. I
> don't know what the username value i
On Tue, 25 Oct 2005 09:37:09 -0700, [EMAIL PROTECTED] wrote:
> I have a config file with the following contents:
> service A = {
> params {
> dir = "c:\test",
> username = "test",
> password = "test"
> }
> }
>
> I want to find username and replace the value with another value. I
>
[EMAIL PROTECTED] wrote:
> I have a config file with the following contents:
> service A = {
> params {
> dir = "c:\test",
> username = "test",
> password = "test"
> }
> }
>
> I want to find username and replace the value with another value. I
> don't know what the username value i
[EMAIL PROTECTED] wrote:
> I have a config file with the following contents:
> service A = {
> params {
> dir = "c:\test",
> username = "test",
> password = "test"
> }
> }
>
> I want to find username and replace the value with another value. I
> don't know what the username value i
I have a config file with the following contents:
service A = {
params {
dir = "c:\test",
username = "test",
password = "test"
}
}
I want to find username and replace the value with another value. I
don't know what the username value in advance though. How to do it in
python?
--
Xah Lee <[EMAIL PROTECTED]> wrote:
> if i have
> mytext.replace(a,b)
> how to find out many many occurances has been replaced?
If 'a' and 'b' are different length,
- Count the string length, before and after. The difference should
be multiple of difference between length of 'a' and 'b'.
"Jeff Epler" wrote:
> On Sun, Jun 12, 2005 at 04:55:38PM -0700, Xah Lee wrote:
> > if i have
> > mytext.replace(a,b)
> > how to find out many many occurances has been replaced?
>
> The count isn't returned by the replace method. You'll have to count
> and then replace.
>
> def count_replace(a, b,
On Sun, Jun 12, 2005 at 04:55:38PM -0700, Xah Lee wrote:
> if i have
> mytext.replace(a,b)
> how to find out many many occurances has been replaced?
The count isn't returned by the replace method. You'll have to count
and then replace.
def count_replace(a, b, c):
count = a.count(b)
retur
if i have
mytext.replace(a,b)
how to find out many many occurances has been replaced?
Xah
[EMAIL PROTECTED]
∑ http://xahlee.org/
--
http://mail.python.org/mailman/listinfo/python-list
Sean McIlroy wrote:
Alright, now it's too much. It's not enough that you're eliminating it
from the language, you have to stigmatize the lambda as well.
You misunderstand me. I don't have a problem with lambda when it's
appropriate, e.g. when used as an expression, where a statement is
forbidden
Alright, now it's too much. It's not enough that you're eliminating it
from the language, you have to stigmatize the lambda as well. You
should take some time to reflect that not everybody thinks the same
way. Those of us who are mathematically inclined like the lambda
because it fits in well with
Sean McIlroy wrote:
f = lambda x: (x[0]=='@' and x[6:] + '.0') or (x=='/' and x + '\n') or
x
See "Inappropriate use of Lambda" in
http://www.python.org/moin/DubiousPython.
You're creating a named function, so there's no reason to use the
anonymous function syntax. Try:
def f(x):
return (x[
I can't claim to have studied your problem in detail, but I get
reasonable results from the following:
filename = 'Errors.txt'
S = open(filename,'r').read().split()
f = lambda x: (x[0]=='@' and x[6:] + '.0') or (x=='/' and x + '\n') or
x
open(filename,'w').write(' '.join(map(f,S)))
HTH
-
[EMAIL PROTECTED] wrote:
Hello NG,
probably this is a basic question, but I'm going crazy... I am unable
to find an answer. Suppose that I have a file (that I called "Errors.txt")
which contains these lines:
MULTIPLY
'PERMX' @PERMX1 1 34 1 20 1 6 /
'PERMX' @PERMX2 1 34 21 41
Hello Peter And NG,
thank you a lot... now I'm blaming myself, how couldn't I see it? I
will probably go for the re.sub (if it is not too complicated, I'm not a
Python expert and even less expert of RegEx things), if not I'll try your
suggestion of sorting the strings by length.
Thanks a lo
[EMAIL PROTECTED] wrote:
'PERMX' @PERMX1 1 34 1 20 1 6 /
...
'PERMX' @PERMX10 1 34 21 41 29 34/
...
I would like to replace all the occurrencies of the "keywords" (beginning
with the @ (AT) symbol) with some floating point value. As an example, this
is what I do:
# Find All Keyw
Hello NG,
probably this is a basic question, but I'm going crazy... I am unable
to find an answer. Suppose that I have a file (that I called "Errors.txt")
which contains these lines:
MULTIPLY
'PERMX' @PERMX1 1 34 1 20 1 6 /
'PERMX' @PERMX2 1 34 21 41 1 6 /
'PERMX' @P
93 matches
Mail list logo