On 10/7/2014 1:01 PM, Ned Batchelder wrote:
On 10/7/14 2:10 AM, Gelonida N wrote:
Disadvantage of itertools.product() is, that it makes a copy in memory.
Reason ist, that itertools also makes products of generators (meaning of
objects, that one can't iterate several times through)
There are t
On 10/7/14 2:10 AM, Gelonida N wrote:
Disadvantage of itertools.product() is, that it makes a copy in memory.
Reason ist, that itertools also makes products of generators (meaning of
objects, that one can't iterate several times through)
There are two use cases, that I occasionaly stumble over
On 8/6/2014 1:39 PM, Tim Chase wrote:
On 2014-08-06 11:04, Gayathri J wrote:
Below is the code I tried to check if itertools.product() was
faster than normal nested loops...
they arent! arent they supposed to be...or am i making a mistake?
I believe something like this was discussed a while a
Dear Peter
thanks . But thats what I was trying to say
just taking them to zero by f[:,:,:] = 0.0 or using np.zeros is surely
going to give me a time gain...
but my example of using the itertools.product() and doing f[x] =0.0 is just
to compare the looping timing with the traditional nested loops
On 2014-08-06 11:04, Gayathri J wrote:
> Below is the code I tried to check if itertools.product() was
> faster than normal nested loops...
>
> they arent! arent they supposed to be...or am i making a mistake?
I believe something like this was discussed a while ago and there was
a faster-but-ugli
Gayathri J wrote:
> Dear Peter
>
> Yes the f[t] or f[:,:,:] might give a marginal increase,
The speedup compared itertools.product() is significant:
$ python -m timeit -s 'from itertools import product; from numpy.random
import rand; N = 100; a = rand(N, N, N); r = range(N)' 'for x in produc
Dear Peter
Yes the f[t] or f[:,:,:] might give a marginal increase, but then i need
to do further operations using the indices, in which case this wouldnt help
Dear Wojciech
np.flat() works if u dont care about the indices and only the matrix/array
values matter.
but if the matters, flatten
You might check numpy it is really powerful tool for working with multi
dimensional arrays:
ex.
>>> a = arange(81).reshape(3,3,3,3)
>>> a
array( 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8]],
[[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17]],
[[18, 1
Gayathri J wrote:
> Dear Peter
>
> Below is the code I tried to check if itertools.product() was faster than
> normal nested loops...
>
> they arent! arent they supposed to be...
I wouldn't have expected product() to be significantly faster, but neither
did I expect it to be slower.
> or am i
On 06/08/2014 06:34, Gayathri J wrote:
Dear Peter
Below is the code I tried to check if itertools.product() was faster
than normal nested loops...
they arent! arent they supposed to be...or am i making a mistake? any idea?
*
*
*
*
*# -
On Wed, Aug 6, 2014 at 3:34 PM, Gayathri J wrote:
> Below is the code I tried to check if itertools.product() was faster than
> normal nested loops...
>
> they arent! arent they supposed to be...or am i making a mistake? any idea?
Don't worry about what's faster. That almost never matters. Worry,
Dear Peter
Below is the code I tried to check if itertools.product() was faster than
normal nested loops...
they arent! arent they supposed to be...or am i making a mistake? any idea?
**
*# -*- coding: utf-8 -*-*
*import numpy as np*
On Tue, 05 Aug 2014 20:06:05 +, Frank Miles wrote:
> I need to evaluate a complicated function over a multidimensional space
> as part of an optimization problem. This is a somewhat general problem
> in which the number of dimensions and the function being evaluated can
> vary from problem to
Frank Miles wrote:
> I need to evaluate a complicated function over a multidimensional space
> as part of an optimization problem. This is a somewhat general problem
> in which the number of dimensions and the function being evaluated can
> vary from problem to problem.
>
> I've got a working ve
Thank you, everyone, for the answers. Very helpful and knowledge-
expanding.
--
http://mail.python.org/mailman/listinfo/python-list
A Counter is definitely the way to go about this. Just as a little more
information. The below example can be simplified:
from collections import Counter
count = Counter(mylist)
With the other example, you could have achieved the same thing (and been
backward compatible to python2.
On 4/25/13, Denis McMahon wrote:
> On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote:
>
>> I have to count the number of various two-digit sequences in a list such
>> as this:
>>
>> mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence
>> appears 2 times.)
>>
>> and tally up the resu
On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote:
> I have to count the number of various two-digit sequences in a list such
> as this:
>
> mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence
> appears 2 times.)
>
> and tally up the results, assigning each to a variable. The in
25.04.13 08:26, Chris Angelico написав(ла):
So you can count them up directly with a dictionary:
count = {}
for sequence_tuple in list_of_tuples:
count[sequence_tuple] = count.get(sequence_tuple,0) + 1
Or alternatives:
count = {}
for sequence_tuple in list_of_tuples:
if sequence_tup
On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote:
> I have to count the number of various two-digit sequences in a list such
> as this:
>
> mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence
> appears 2 times.)
>
> and tally up the results, assigning each to a variable. The in
On Thu, Apr 25, 2013 at 3:05 PM, CM wrote:
> I have to count the number of various two-digit sequences in a list
> such as this:
>
> mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4)
> sequence appears 2 times.)
>
> and tally up the results, assigning each to a variable.
You can use
On 03/05/2013 01:48 AM, Lowly Minion wrote:
For a typical dict:
i.e.
d = { '1': 'a', '2', 'b' }
I might use something like:
d.get('1', None)
To get the value of 1.
What would be the most pythonic way of getting a nested value of a dictionary
within a list:
some_list = [{ 'item': { 'letter'
On Fri, Nov 2, 2012 at 7:58 PM, jack wrote:
> thanks,but I don't think enumerate() is my want
> Have some ways to operate the reference of element,not a copy when I tried
> to traverse a list?
>
> I'm so sorry about my poor English, hope you don't mind it.
No probs, I'll be a little less vague an
thanks,but I don't think enumerate() is my want
Have some ways to operate the reference of element,not a copy when I
tried to traverse a list?
I'm so sorry about my poor English, hope you don't mind it.
On 2012/11/2 15:56, Chris Angelico wrote:
On Fri, Nov 2, 2012 at 6:14 PM, jack wrote:
So
On Fri, Nov 2, 2012 at 6:14 PM, jack wrote:
> Sometimes, I need to alter the element as traverse a list like this (it's a
> sample):
> c = range(10)
> i = 0
> for ele in c:
> # do something
> # branch:
> c[i] = # value
> i += 1
>
> How to be pythonic
Sometimes, I need to alter the element as traverse a list like this
(it's a sample):
c = range(10)
i = 0
for ele in c:
# do something
# branch:
c[i] = # value
i += 1
How to be pythonic?
2012/11/2 0:54, Zero Piraeus :
:
On 1 November 2012 11:32,
OK ..I got it..
On Thu, Nov 1, 2012 at 5:54 PM, Zero Piraeus wrote:
> :
>
> On 1 November 2012 11:32, inshu chauhan wrote:
> > what is the most pythonic way to do this :
> >
> >if 0 < ix < 10 and 0 < iy < 10 ???
>
> As everyone else has said, it's perfectly pythonic once yo
:
On 1 November 2012 11:32, inshu chauhan wrote:
> what is the most pythonic way to do this :
>
>if 0 < ix < 10 and 0 < iy < 10 ???
As everyone else has said, it's perfectly pythonic once you stick the
colon on the end. You might find it more instantly readable with some
ext
On Thu, Nov 1, 2012 at 9:32 AM, inshu chauhan wrote:
> what is the most pythonic way to do this :
>
>if 0 < ix < 10 and 0 < iy < 10 ???
>
I suppose you could do
if all(0 < i < 10 for i in (ix, iy)):
but I think that the original is more readable unless you have several
On 11/1/2012 11:32 AM, inshu chauhan wrote:
what is the most pythonic way to do this :
if 0 < ix < 10 and 0 < iy < 10 ???
end with : instead of ???
>>> ix, iy = 3,4
>>> if 0 < ix < 10 and 0 < iy < 10:
print('This was too easy')
This was too easy
--
Ter
On 11/01/12 10:32, inshu chauhan wrote:
> what is the most pythonic way to do this :
>
>if 0 < ix < 10 and 0 < iy < 10 ???
What's wrong with the syntax you provide? It's perfectly pythonic:
ix = 42
yx = 3.14159
if 0 < ix < 10 and 0 < iy < 10:
do_stuff(ix, iy)
el
On 2012-11-01 15:32, inshu chauhan wrote:
what is the most pythonic way to do this :
if 0 < ix < 10 and 0 < iy < 10 ???
That looks Pythonic to me, except for the missing colon.
--
http://mail.python.org/mailman/listinfo/python-list
Thanks, everyone. Very helpful!
Che
--
http://mail.python.org/mailman/listinfo/python-list
On 20/07/11 06:19, Steven D'Aprano wrote:
> On Wed, 20 Jul 2011 01:17 pm CM wrote:
>
>> I have three items in a dict, like this:
>>
>> the_dict = {'a':1, 'b':2, 'c':3}
>>
>> but the vals could be anything. I want to configure something else
>> based on the "winner" of such a dict, with these rule
On Tue, Jul 19, 2011 at 10:10 PM, CM wrote:
> On Jul 19, 11:17 pm, CM wrote:
>> I have three items in a dict, like this:
>>
>> the_dict = {'a':1, 'b':2, 'c':3}
>>
>> but the vals could be anything. I want to configure something else
>> based on the "winner" of such a dict, with these rules:
> I
> 1. In this dict, if there is a UNIQUE max value, then its *key* is the
> winner.
> 2. If there are any TIES for max value, then the *key* 'b' is the
> winner by default.
This will store the max value(s) in a list. In case of a tie, you can
take the first value in the list, but it may be differe
On Jul 19, 11:17 pm, CM wrote:
> I have three items in a dict, like this:
>
> the_dict = {'a':1, 'b':2, 'c':3}
>
> but the vals could be anything. I want to configure something else
> based on the "winner" of such a dict, with these rules:
>
> 1. In this dict, if there is a UNIQUE max value, that
On Tue, Jul 19, 2011 at 8:17 PM, CM wrote:
> I have three items in a dict, like this:
>
> the_dict = {'a':1, 'b':2, 'c':3}
>
> but the vals could be anything. I want to configure something else
> based on the "winner" of such a dict, with these rules:
>
> 1. In this dict, if there is a UNIQUE max
On Wed, 20 Jul 2011 01:17 pm CM wrote:
> I have three items in a dict, like this:
>
> the_dict = {'a':1, 'b':2, 'c':3}
>
> but the vals could be anything. I want to configure something else
> based on the "winner" of such a dict, with these rules:
>
> 1. In this dict, if there is a UNIQUE max
On Oct 31, 4:27 pm, Lawrence D'Oliveiro wrote:
> In message
> <687bcb76-0093-4d68-ba56-0390a3e1e...@30g2000yql.googlegroups.com>,
>
> cbr...@cbrownsystems.com wrote:
> > I should note that efficiency is not an issue to me here; this is for
> > when you have, say, a list user_options of at most aro
In message
<687bcb76-0093-4d68-ba56-0390a3e1e...@30g2000yql.googlegroups.com>,
cbr...@cbrownsystems.com wrote:
> I should note that efficiency is not an issue to me here; this is for
> when you have, say, a list user_options of at most around 15 options
> or so, and you want to perform some actio
In message <4cca5aaf$0$1600$742ec...@news.sonic.net>, John Nagle wrote:
> This is cheaper than intersection ...
All together now:
“PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL!”
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 29, 2:43 am, Steven D'Aprano wrote:
> On Thu, 28 Oct 2010 09:16:42 -0700, cbr...@cbrownsystems.com wrote:
> > It's clear but tedious to write:
>
> > if 'monday" in days_off or "tuesday" in days_off:
> > doSomething
>
> > I currently am tending to write:
>
> > if any([d for d in ['monday
cbr...@cbrownsystems.com wrote:
> It's clear but tedious to write:
>
> if 'monday" in days_off or "tuesday" in days_off:
>doSomething
>
> I currently am tending to write:
>
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
>doSomething
>
> Is there a better pythonic idiom
On Thu, 28 Oct 2010 09:16:42 -0700, cbr...@cbrownsystems.com wrote:
> It's clear but tedious to write:
>
> if 'monday" in days_off or "tuesday" in days_off:
> doSomething
>
> I currently am tending to write:
>
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
> doSomething
Not sure why you use the for-else syntax without a break or continue. And
I'm also not sure on the readability.
-Xav on his Froyo
On 29/10/2010 6:21 PM, "HEK" wrote:
> On Oct 28, 6:16 pm, "cbr...@cbrownsystems.com"
> wrote:
>> It's clear but tedious to write:
>>
>> if 'monday" in days_off or "tu
On Oct 28, 6:16 pm, "cbr...@cbrownsystems.com"
wrote:
> It's clear but tedious to write:
>
> if 'monday" in days_off or "tuesday" in days_off:
> doSomething
>
> I currently am tending to write:
>
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
> doSomething
>
> Is there a be
On Oct 28, 10:50 pm, Paul Rubin wrote:
> John Nagle writes:
> > d1 = set('monday','tuesday')
> > days_off = set('saturday','sunday')
> > if not d1.isdisjoint(days_off) :...
> > This is cheaper than intersection, since it doesn't have to
> > allocate and construct a set. It just tests
On Oct 28, 11:56 am, Arnaud Delobelle wrote:
> "cbr...@cbrownsystems.com" writes:
> > It's clear but tedious to write:
>
> > if 'monday" in days_off or "tuesday" in days_off:
> > doSomething
>
> > I currently am tending to write:
>
> > if any([d for d in ['monday', 'tuesday'] if d in days_off
On 29 October 2010 15:50, Paul Rubin wrote:
> John Nagle writes:
> >d1 = set('monday','tuesday')
> >days_off = set('saturday','sunday')
> >if not d1.isdisjoint(days_off) :...
> >This is cheaper than intersection, since it doesn't have to
> > allocate and construct a set. It just
John Nagle writes:
>d1 = set('monday','tuesday')
>days_off = set('saturday','sunday')
>if not d1.isdisjoint(days_off) :...
>This is cheaper than intersection, since it doesn't have to
> allocate and construct a set. It just tests whether any element in the
> smaller of the two sets
On 10/28/2010 9:23 AM, John Posner wrote:
On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
It's clear but tedious to write:
if 'monday" in days_off or "tuesday" in days_off:
doSomething
I currently am tending to write:
if any([d for d in ['monday', 'tuesday'] if d in days_off]):
doSome
"cbr...@cbrownsystems.com" writes:
> It's clear but tedious to write:
>
> if 'monday" in days_off or "tuesday" in days_off:
> doSomething
>
> I currently am tending to write:
>
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
> doSomething
>
> Is there a better pythonic idio
On Oct 28, 10:05 am, Chris Rebert wrote:
> On Thu, Oct 28, 2010 at 9:33 AM, cbr...@cbrownsystems.com
>
>
>
> wrote:
> > On Oct 28, 9:23 am, John Posner wrote:
> >> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>
> >> > It's clear but tedious to write:
>
> >> > if 'monday" in days_off o
On Oct 28, 12:33 pm, "cbr...@cbrownsystems.com"
wrote:
> On Oct 28, 9:23 am, John Posner wrote:
>
>
>
> > On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>
> > > It's clear but tedious to write:
>
> > > if 'monday" in days_off or "tuesday" in days_off:
> > > doSomething
>
> > > I cur
On Thu, Oct 28, 2010 at 9:33 AM, cbr...@cbrownsystems.com
wrote:
> On Oct 28, 9:23 am, John Posner wrote:
>> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>>
>> > It's clear but tedious to write:
>>
>> > if 'monday" in days_off or "tuesday" in days_off:
>> > doSomething
>>
>> > I c
On Thu, Oct 28, 2010 at 9:16 AM, cbr...@cbrownsystems.com <
cbr...@cbrownsystems.com> wrote:
> It's clear but tedious to write:
>
> if 'monday" in days_off or "tuesday" in days_off:
>doSomething
>
> I currently am tending to write:
>
> if any([d for d in ['monday', 'tuesday'] if d in days_off]
On Oct 28, 9:23 am, John Posner wrote:
> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>
> > It's clear but tedious to write:
>
> > if 'monday" in days_off or "tuesday" in days_off:
> > doSomething
>
> > I currently am tending to write:
>
> > if any([d for d in ['monday', 'tuesday']
On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
It's clear but tedious to write:
if 'monday" in days_off or "tuesday" in days_off:
doSomething
I currently am tending to write:
if any([d for d in ['monday', 'tuesday'] if d in days_off]):
doSomething
Is there a better pythonic
On 03/23/10 23:38, Tim Chase wrote:
Just in case you're okay with a regexp solution, you can use
>>> s = "\t\tabc def "
>>> import re
>>> r = re.compile(r'^(\s*)(.*?)(\s*)$')
>>> m = re.match(s)
>>> m.groups()
('\t\t', 'abc def', ' ')
>>> leading, text, trailing = m.groups()
Ahhh regex,
pyt...@bdurham.com wrote:
I'm looking for a pythonic way to trim and keep leading
whitespace in a string.
Use case: I have a bunch of text strings with various amounts of
leading and trailing whitespace (spaces and tabs). I want to grab
the leading and trailing whitespace, save it, surround the
regex is not goto that you should always avoid using it. It have its own
use-case, here regex solution is intuitive although @emile have done this
for you via string manpulation.
On Wed, Mar 24, 2010 at 4:09 AM, Daniel Chiquito
wrote:
> As far as I know, I don't think there is anything that strip
uot;Emile van Sebille"
To: python-list@python.org
Date: Tue, 23 Mar 2010 15:34:48 -0700
Subject: Re: Pythonic way to trim and keep leading and trailing
whitespace
On 3/23/2010 3:09 PM pyt...@bdurham.com said...
> I'm looking for a pythonic way to trim and keep leading
> whitespace in
As far as I know, I don't think there is anything that strips it and returns
the material that was stripped. Regex's would be your best bet.
Daniel
On Tue, Mar 23, 2010 at 6:09 PM, wrote:
> I'm looking for a pythonic way to trim and keep leading whitespace in a
> string.
>
> Use case: I have a
On 3/23/2010 3:09 PM pyt...@bdurham.com said...
I'm looking for a pythonic way to trim and keep leading
whitespace in a string.
Use case: I have a bunch of text strings with various amounts of
leading and trailing whitespace (spaces and tabs). I want to grab
the leading and trailing whitespace,
On Wed, 2009-06-17 at 14:26 -0400, Cameron Pulsford wrote:
> This is only supposed to handle text files, so when would reading it
> all into memory become too much for most computers? I'm guessing there
> aren't many source files of too great a size.
I often use python with server log files - 1Tb
Top-posting, tsk, tsk.
On Wed, 17 Jun 2009 19:26:07 +0100, Cameron Pulsford
wrote:
Essentially it just cleans up a source file of erroneous spaces and tabs
and
can also convert tabs to spaces so loading the whole file into memory is
possibly an option. I am making this utility for persona
Essentially it just cleans up a source file of erroneous spaces and tabs and
can also convert tabs to spaces so loading the whole file into memory is
possibly an option. I am making this utility for personal use, and that
would definitely be fine, but if it turned out well I'd open source it and
th
Cameron Pulsford wrote:
Hey all, hopefully a simple question.
I'm writing a simple python tool that opens a file, and does something
like
for line in file.readlines():
temp.write(line.doStuff())
However, I want to provide the option do this "in place", as in have
the destination file be
Cameron Pulsford wrote:
> Hey all, hopefully a simple question.
>
> I'm writing a simple python tool that opens a file, and does something like
>
> for line in file.readlines():
> temp.write(line.doStuff())
>
> However, I want to provide the option do this "in place", as in have the
> desti
On Fri, May 8, 2009 at 8:53 AM, wrote:
> I'm looking for suggestions on technique (not necessarily code) about the
> most pythonic way to normalize vertical whitespace in blocks of text so that
> there is never more than 1 blank line between paragraphs. Our source text
> has newlines normalized
On Feb 21, 2:24 pm, rdmur...@bitdance.com wrote:
> odeits wrote:
> > On Feb 21, 12:47=A0am, "Gabriel Genellina"
> > wrote:
> > > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi=F3:
>
> > > > On Feb 15, 11:31=A0pm, odeits wrote:
> > > >> It seems what you are actually testing for is if the in
odeits wrote:
> On Feb 21, 12:47=A0am, "Gabriel Genellina"
> wrote:
> > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi=F3:
> >
> > > On Feb 15, 11:31=A0pm, odeits wrote:
> > >> It seems what you are actually testing for is if the intersection of
> > >> the two sets is not empty where the fi
On Feb 21, 12:47 am, "Gabriel Genellina"
wrote:
> En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribió:
>
>
>
> > On Feb 15, 11:31 pm, odeits wrote:
> >> It seems what you are actually testing for is if the intersection of
> >> the two sets is not empty where the first set is the characters in
>
En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribió:
On Feb 15, 11:31 pm, odeits wrote:
It seems what you are actually testing for is if the intersection of
the two sets is not empty where the first set is the characters in
your word and the second set is the characters in your defined strin
On Feb 15, 11:31 pm, odeits wrote:
> On Feb 15, 9:56 pm, Chris Rebert wrote:
>
>
>
> > On Sun, Feb 15, 2009 at 9:17 PM, wrote:
> > > I need to test strings to determine if one of a list of chars is in the
> > > string. A simple example would be to test strings to determine if they
> > > have
>
MRAB wrote:
Dennis Lee Bieber wrote:
On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__pete...@web.de>
declaimed the following in comp.lang.python:
Steve Holden wrote:
Jervis Whitley wrote:
What happens when you have hundreds of megabytes, I don't know.
I hope I never have to test a wor
Dennis Lee Bieber wrote:
On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__pete...@web.de>
declaimed the following in comp.lang.python:
Steve Holden wrote:
Jervis Whitley wrote:
What happens when you have hundreds of megabytes, I don't know.
I hope I never have to test a word that is hun
On Feb 19, 6:47 pm, Dennis Lee Bieber wrote:
> On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__pete...@web.de>
> declaimed the following in comp.lang.python:
>
> > Steve Holden wrote:
>
> > > Jervis Whitley wrote:
> > >>> What happens when you have hundreds of megabytes, I don't know.
>
> > >>
Steve Holden wrote:
> Jervis Whitley wrote:
>>> What happens when you have hundreds of megabytes, I don't know.
>>>
>>>
>> I hope I never have to test a word that is hundreds of megabytes long
>> for a vowel :)
>
> I see you don't speak German ;-)
I tried to come up with a funny way to point out
Steven D'Aprano wrote:
> On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote:
>
>
>>> This moves the for-loop out of slow Python into fast C and should be
>>> much, much faster for very large input.
>>>
>>>
>> _Should_ be faster.
>
> Yes, Python's timing results are often unintuitive.
Ind
Jervis Whitley wrote:
>> What happens when you have hundreds of megabytes, I don't know.
>>
>>
> I hope I never have to test a word that is hundreds of megabytes long
> for a vowel :)
I see you don't speak German ;-)
--
Steve Holden+1 571 484 6266 +1 800 494 3119
Holden Web LLC
>
> What happens when you have hundreds of megabytes, I don't know.
>
>
I hope I never have to test a word that is hundreds of megabytes long
for a vowel :)
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote:
>> This moves the for-loop out of slow Python into fast C and should be
>> much, much faster for very large input.
>>
>>
> _Should_ be faster.
Yes, Python's timing results are often unintuitive.
> Here is my test on an XP system Python
>
> This moves the for-loop out of slow Python into fast C and should be much,
> much faster for very large input.
>
_Should_ be faster.
Here is my test on an XP system Python 2.5.4. I had similar results on
python 2.7 trunk.
WORD = 'g' * 100
WORD2 = 'g' * 50 + 'U'
BIGWORD = 'g' * 1 + 'U'
Original poster here: Just for the record, my *original* post did
include an explicit trapping of the ValueError exception. :)
My point is that the coaching offered by this forum does not always fall
on deaf ears.
Thanks for everyone's help on this and all the other posts in this
forum.
Regards
2009/2/16 Python Nutter :
> silly me, forgot to mention
>
> build a set from digits + '.' and use that for testing.
>
> Cheers,
> PN
>
>
> 2009/2/16 Python Nutter :
>> Type casting seems to be the wrong way to go about this.
>>
>> teststring = '15719'
>> teststring.isdigit()
>> returns True
>>
>> T
On Feb 16, 7:09 am, Python Nutter wrote:
> silly me, forgot to mention
>
> build a set from digits + '.' and use that for testing.
`.' is locale dependent. Some locales might use `,' instead and maybe
there's even more out there that I don't know of. So developing this
yourself from scratch see
On Feb 16, 12:05 am, Mel wrote:
> Christian Heimes wrote:
> > Roy Smith wrote:
> >> They make sense when you need to recover from any error that may occur,
> >> possibly as the last resort after catching and dealing with more specific
> >> exceptions. In an unattended embedded system (think Mars R
In article <01aaa1da$0$20629$c3e8...@news.astraweb.com>,
Steven D'Aprano wrote:
> Okay, but that surely falls under chapter 18 of the "Advanced Python
> Programming for the Mars Rover" book rather than chapter 5 of "Newbies
> Guide to Python".
Well, sure, but this thread started out with my tak
Roy Smith wrote:
>> > Do you really want to except SystemExit, KeyboardInterrupt, MemoryError
>> > and SyntaxError?
>
> Absolutely. Let's take my example -- you're writing software for a Mars
> Rover. I have no idea how you might get a MemoryError, but let's say you
> do. Which would you rathe
Nicolas Dandrimont wrote:
> I would go for something like:
>
> for char in word:
> if char in 'aeiouAEIUO':
> char_found = True
> break
> else:
> char_found = False
>
> (No, I did not forget to indent the else statement, see
> http://docs.python.org/reference/compound_stm
On Feb 15, 5:46 pm, pyt...@bdurham.com wrote:
> What's the Pythonic way to determine if a string is a number? By
> number I mean a valid integer or float.
>
> I searched the string and cMath libraries for a similar function
> without success. I can think of at least 3 or 4 ways to build my
> own fu
pyt...@bdurham.com wrote:
> Thanks for everyone's feedback. I believe my original post's code
> (updated following my signature) was in line with this list's feedback.
>
> Christian: Thanks for reminding me about exponential formats. My updated
> code accounts for these type of numbers. I don
An entirely different approach would be to use a regular expression:
import re
if re.search("[abc]", "nothing expekted"):
print "a, b or c occurs in the string 'nothing expekted'"
if re.search("[abc]", "something expected"):
print "a, b or c occurs in the string 'something expected'"
Best
On Mon, 2009-02-16 at 00:28 -0500, Nicolas Dandrimont wrote:
> * pyt...@bdurham.com [2009-02-16 00:17:37 -0500]:
>
> > I need to test strings to determine if one of a list of chars is
> > in the string. A simple example would be to test strings to
> > determine if they have a vowel (aeiouAEIOU)
* pyt...@bdurham.com [2009-02-16 00:48:34 -0500]:
> Nicolas,
>
> > I would go for something like:
> >
> > for char in word:
> > if char in 'aeiouAEIUO':
> > char_found = True
> > break
> > else:
> > char_found = False
> >
> > It is clear (imo), and it is seems to be the
[Resending after a bounce from mailing list]
pyt...@bdurham.com wrote:
try:
float (input)
except ValueError:
return False
else:
return True
I follow the semantics, but I don't know why I would prefer the try/else
technique over the simpler:
try:
float( input )
return True
exc
On Feb 15, 9:56 pm, Chris Rebert wrote:
> On Sun, Feb 15, 2009 at 9:17 PM, wrote:
> > I need to test strings to determine if one of a list of chars is in the
> > string. A simple example would be to test strings to determine if they have
> > a vowel (aeiouAEIOU) present.
>
> > I was hopeful that
Roy Smith wrote:
In article ,
Mel wrote:
Christian Heimes wrote:
Roy Smith wrote:
They make sense when you need to recover from any error that may occur,
possibly as the last resort after catching and dealing with more specific
exceptions. In an unattended embedded system (think Mars Rover)
1 - 100 of 193 matches
Mail list logo