On May 10, 2:25 am, Stefan Behnel wrote:
> Stefan Behnel, 10.05.2010 08:54:
>
>
>
>
>
> > dasacc22, 08.05.2010 19:19:
> >> This is a simple question. I'm looking for the fastest way to
> >> calculate the leading whitespace (as a string, ie ' ').
>
> > Here is an (untested) Cython 0.13 solution:
>
Stefan Behnel, 10.05.2010 08:54:
dasacc22, 08.05.2010 19:19:
This is a simple question. I'm looking for the fastest way to
calculate the leading whitespace (as a string, ie ' ').
Here is an (untested) Cython 0.13 solution:
from cpython.unicode cimport Py_UNICODE_ISSPACE
def leading_w
dasacc22, 08.05.2010 19:19:
This is a simple question. I'm looking for the fastest way to
calculate the leading whitespace (as a string, ie '').
Here is an (untested) Cython 0.13 solution:
from cpython.unicode cimport Py_UNICODE_ISSPACE
def leading_whitespace(unicode ustring):
On May 9, 8:28 am, John Machin wrote:
> dasacc22 gmail.com> writes:
>
>
>
> > U presume entirely to much. I have a preprocessor that normalizes
> > documents while performing other more complex operations. Theres
> > nothing buggy about what im doing
>
> Are you sure?
>
> Your "solution" calcula
On May 9, 6:13 am, Steven D'Aprano wrote:
> On Sat, 08 May 2010 13:46:59 -0700, Mark Dickinson wrote:
> >> However, s[:-len(t)] should be both faster and correct.
>
> > Unless len(t) == 0, surely?
>
> Doh! The hazards of insufficient testing. Thanks for catching that.
I have a love-hate relations
dasacc22 gmail.com> writes:
>
> U presume entirely to much. I have a preprocessor that normalizes
> documents while performing other more complex operations. Theres
> nothing buggy about what im doing
Are you sure?
Your "solution" calculates (the number of leading whitespace characters) + (th
On 8 Mai, 21:46, Steven D'Aprano wrote:
> On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote:
> > Returning s[:-1 - len(t)] is faster.
>
> I'm sure it is. Unfortunately, it's also incorrect.
> However, s[:-len(t)] should be both faster and correct.
Ouch. Thanks for correcting me.
No, I'
On Sat, 08 May 2010 14:27:32 -0700, dasacc22 wrote:
> U presume entirely to much. I have a preprocessor that normalizes
> documents while performing other more complex operations. Theres
> nothing buggy about what im doing
I didn't *presume* anything, I took your example code and ran it and
dis
On Sat, 08 May 2010 13:46:59 -0700, Mark Dickinson wrote:
>> However, s[:-len(t)] should be both faster and correct.
>
> Unless len(t) == 0, surely?
Doh! The hazards of insufficient testing. Thanks for catching that.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On May 8, 2:46 pm, Steven D'Aprano wrote:
> On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote:
> > On 8 Mai, 20:46, Steven D'Aprano
> > wrote:
>
> >> def get_leading_whitespace(s):
> >> t = s.lstrip()
> >> return s[:len(s)-len(t)]
>
> >> >>> c = get_leading_whitespace(a)
> >> >>>
On May 8, 5:18 pm, Patrick Maupin wrote:
> On May 8, 1:16 pm, dasacc22 wrote:
>
>
>
>
>
> > On May 8, 12:59 pm, Patrick Maupin wrote:
>
> > > On May 8, 12:19 pm, dasacc22 wrote:
>
> > > > Hi
>
> > > > This is a simple question. I'm looking for the fastest way to
> > > > calculate the leading wh
On May 8, 1:16 pm, dasacc22 wrote:
> On May 8, 12:59 pm, Patrick Maupin wrote:
>
>
>
> > On May 8, 12:19 pm, dasacc22 wrote:
>
> > > Hi
>
> > > This is a simple question. I'm looking for the fastest way to
> > > calculate the leading whitespace (as a string, ie ' ').
>
> > > Here are some dif
U presume entirely to much. I have a preprocessor that normalizes
documents while performing other more complex operations. Theres
nothing buggy about what im doing
On May 8, 1:46 pm, Steven D'Aprano wrote:
> On Sat, 08 May 2010 10:19:16 -0700, dasacc22 wrote:
> > Hi
>
> > This is a simple quest
On May 8, 8:46 pm, Steven D'Aprano wrote:
> On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote:
> > On 8 Mai, 20:46, Steven D'Aprano
> > wrote:
>
> >> def get_leading_whitespace(s):
> >> t = s.lstrip()
> >> return s[:len(s)-len(t)]
>
> >> >>> c = get_leading_whitespace(a)
> >> >>>
On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote:
> On 8 Mai, 20:46, Steven D'Aprano
> wrote:
>
>> def get_leading_whitespace(s):
>> t = s.lstrip()
>> return s[:len(s)-len(t)]
>>
>> >>> c = get_leading_whitespace(a)
>> >>> assert c == leading_whitespace
>>
>> Unless your string
On 8 Mai, 20:46, Steven D'Aprano wrote:
> def get_leading_whitespace(s):
> t = s.lstrip()
> return s[:len(s)-len(t)]
>
> >>> c = get_leading_whitespace(a)
> >>> assert c == leading_whitespace
>
> Unless your strings are very large, this is likely to be faster than any
> other pure-Python
On Sat, 08 May 2010 10:19:16 -0700, dasacc22 wrote:
> Hi
>
> This is a simple question. I'm looking for the fastest way to calculate
> the leading whitespace (as a string, ie '').
Is calculating the amount of leading whitespace really the bottleneck in
your application? If not, then trying
On May 8, 12:59 pm, Patrick Maupin wrote:
> On May 8, 12:19 pm, dasacc22 wrote:
>
>
>
>
>
> > Hi
>
> > This is a simple question. I'm looking for the fastest way to
> > calculate the leading whitespace (as a string, ie ' ').
>
> > Here are some different methods I have tried so far
> > --- sol
On May 8, 12:19 pm, dasacc22 wrote:
> Hi
>
> This is a simple question. I'm looking for the fastest way to
> calculate the leading whitespace (as a string, ie ' ').
>
> Here are some different methods I have tried so far
> --- solution 1
>
> a = ' some content\n'
> b = a.strip()
> c = ' '*(l
sorry, my mistake it runs faster (looking at the wrong line of code). But
the first two solutions are still faster.
On Sat, May 8, 2010 at 12:48 PM, Daniel Skinner wrote:
> That solution actually runs slower then the generator method.
>
>
> On Sat, May 8, 2010 at 12:33 PM, Shashank Singh <
> sha
That solution actually runs slower then the generator method.
On Sat, May 8, 2010 at 12:33 PM, Shashank Singh <
shashank.sunny.si...@gmail.com> wrote:
>
>
> On Sat, May 8, 2010 at 10:49 PM, dasacc22 wrote:
>
>> Hi
>>
>> This is a simple question. I'm looking for the fastest way to
>> calculate t
On Sat, May 8, 2010 at 10:49 PM, dasacc22 wrote:
> Hi
>
> This is a simple question. I'm looking for the fastest way to
> calculate the leading whitespace (as a string, ie '').
>
> Here are some different methods I have tried so far
> --- solution 1
>
> a = 'some content\n'
> b = a.strip(
Hi
This is a simple question. I'm looking for the fastest way to
calculate the leading whitespace (as a string, ie '').
Here are some different methods I have tried so far
--- solution 1
a = 'some content\n'
b = a.strip()
c = ' '*(len(a)-len(b))
--- solution 2
a = 'some content\n'
23 matches
Mail list logo