Subject
Re:
pairs from a list
23/01/2008 18:32
On 23 Jan, 22:39, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Jan 23, 4:48 pm, Steven D'Aprano <[EMAIL PROTECTED]
>
> cybersource.com.au> wrote:
> > As for your other points, I think we're actually very much in agreement,
> > except for your tolerance of random posters asking what I believe is an
On Jan 23, 4:48 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> As for your other points, I think we're actually very much in agreement,
> except for your tolerance of random posters asking what I believe is an
> incoherent question: "what's the fastest way to do ...?". It seem
On Wed, 23 Jan 2008 11:06:44 -0800, George Sakkis wrote:
> On Jan 23, 1:30 pm, Paddy <[EMAIL PROTECTED]> wrote:
>
>> I've heard quality expressed as "meeting requirements", which I think
>> is apt. Falling short of requirements everyone knows doesn't give a
>> quality result, but equally 'exceedi
fastest
>> * fastest on typical data
>> * all of the above
>
>
> I confess that it did not occur to me that there might be an interesting
> distinction among these cases for the question of how to get sequential
> pairs from a list. How would one draw these distinct
On Wed, 23 Jan 2008 10:39:25 -0800, George Sakkis wrote:
> On Jan 23, 4:37 am, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
>> On Tue, 22 Jan 2008 23:33:00 -0800, George Sakkis wrote:
>> > As I mentioned already, I consider the seeking of the most efficient
>> > solution a legitimate question, reg
On Jan 23, 7:06 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> The OP wanted an answer to a simple question, not a lecture on good
> software engineering principles.
I wholeheartedly agree.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 23, 1:30 pm, Paddy <[EMAIL PROTECTED]> wrote:
> I've heard quality expressed as "meeting requirements", which I think
> is apt. Falling short of requirements everyone knows doesn't give a
> quality result, but equally 'exceeding' requirements also detracts
> from quality (as does not knowin
On Jan 23, 4:37 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Tue, 22 Jan 2008 23:33:00 -0800, George Sakkis wrote:
> > As I mentioned already, I consider the seeking of the most efficient
> > solution a legitimate question, regardless of whether a "dumb" solution
> > is fast enough for an ap
Matthew_WARREN wrote:
> I'm just fiddling with this, am no great expert, but I added
>
> def pairs5(x):
> o=[]
> for n in zip(x[::2],x[1:2]):
The second argument should be x[1::2].
> o.append(n)
> return o
>
> I dont know if that breaks any constraints p
rote:
>
> > > > On Jan 22, 3:20 am, Alan Isaac <[EMAIL PROTECTED]> wrote:> I want to
> > > > generate sequential pairs from a list.
> > > > <>
> > > > > What is the fastest way? (Ignore the import time.)
>
> > > &
n.org
Subject
Re:
pairs from a list
22/01/2008
id not occur to me that there
might be an interesting distinction among these
cases for the question of how to get sequential
pairs from a list. How would one draw these
distinctions in this case?
Thanks,
Alan Isaac
PS Just for context, the sequential pairs were
needed in a simulation, but
On Tue, 22 Jan 2008 23:33:00 -0800, George Sakkis wrote:
> As I mentioned already, I consider the seeking of the most efficient
> solution a legitimate question, regardless of whether a "dumb" solution
> is fast enough for an application. Call it a "don't be sloppy" principle
> if you wish.
Sure,
On Jan 23, 1:39 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> Given the human psychology displayed involved, in the absence of
> definitive evidence one way or another it is a far safer bet to assume
> that people are unnecessarily asking for "the fastest" out of a misguided
> and often ignoran
On Tue, 22 Jan 2008 18:32:22 -0800, George Sakkis wrote:
> The OP didn't mention anything about the context; for all we know, this
> might be a homework problem or the body of a tight inner loop. There is
> this tendency on c.l.py to assume that every optimization question is
> about a tiny subpro
On Jan 22, 1:34 pm, Paddy <[EMAIL PROTECTED]> wrote:
> On Jan 22, 5:34 am, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jan 22, 12:15 am, Paddy <[EMAIL PROTECTED]> wrote:
>
> > > On Jan 22, 3:20 am, Alan Isaac <[EMAIL PROTECTED]> wro
[Peter Otten]
> You can be bolder here as the izip() docs explicitly state
>
> """
> Note, the left-to-right evaluation order of the iterables is
> guaranteed. This makes possible an idiom for clustering a data series into
> n-length groups using "izip(*[iter(s)]*n)".
> """
. . .
> is about zip(),
Arnaud Delobelle wrote:
> On Jan 22, 4:10 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
>
>> http://bugs.python.org/issue1121416>
>>
>> fwiw,
>> Alan Isaac
>
> Thanks. So I guess I shouldn't take the code snippet I quoted as a
> specification of izip but rather as an illustration.
You can be bolde
On Jan 22, 6:34 pm, Paddy <[EMAIL PROTECTED]> wrote:
[...]
> Hi George,
> You need to 'get it right' first. Micro optimizations for speed
> without thought of the wider context is a bad habit to form and a time
> waster.
> If the routine is all that needs to be delivered and it does not
> perform a
On Jan 22, 5:34 am, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Jan 22, 12:15 am, Paddy <[EMAIL PROTECTED]> wrote:
>
> > On Jan 22, 3:20 am, Alan Isaac <[EMAIL PROTECTED]> wrote:> I want to
> > generate sequential pairs from a list.
> > <>
>
Arnaud Delobelle wrote:
> pairs4 wins.
Oops. I see a smaller difference,
but yes, pairs4 wins.
Alan Isaac
import time
from itertools import islice, izip
x = range(51)
def pairs1(x):
return izip(islice(x,0,None,2),islice(x,1,None,2))
def pairs2(x):
xiter = iter(x)
while True:
On Jan 22, 4:10 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
> http://bugs.python.org/issue1121416>
>
> fwiw,
> Alan Isaac
Thanks. So I guess I shouldn't take the code snippet I quoted as a
specification of izip but rather as an illustration.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/
Arnaud Delobelle wrote:
> According to the docs [1], izip is defined to be equivalent to:
>
> def izip(*iterables):
> iterables = map(iter, iterables)
> while iterables:
> result = [it.next() for it in iterables]
> yield tuple(result)
>
> This guar
On Jan 22, 1:19 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
> I suppose my question should have been,
> is there an obviously faster way?
> Anyway, of the four ways below, the
> first is substantially fastest. Is
> there an obvious reason why?
Can you post your results?
I get different ones (pairs
Alan Isaac>What is the fastest way? (Ignore the import time.)<
Maybe someday someone will realize such stuff belongs to the python
STD lib...
If you need a lazy generator without padding, that splits starting
from the start, then this is the faster to me if n is close to 2:
def xpartition(seq, n
On Jan 22, 1:19 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
[...]
> PS My understanding is that the behavior
> of the last is implementation dependent
> and not guaranteed.
[...]
> def pairs4(x):
> xiter = iter(x)
> for x12 in izip(xiter,xiter):
> yield x12
According to the docs [1],
I suppose my question should have been,
is there an obviously faster way?
Anyway, of the four ways below, the
first is substantially fastest. Is
there an obvious reason why?
Thanks,
Alan Isaac
PS My understanding is that the behavior
of the last is implementation dependent
and not guaranteed.
d
On Jan 22, 3:20 am, Alan Isaac <[EMAIL PROTECTED]> wrote:
> I want to generate sequential pairs from a list.
> Here is a way::
>
> from itertools import izip, islice
> for x12 in izip(islice(x,0,None,2),islice(x,1,None,2)):
> print x12
>
> (Of cour
On Mon, 21 Jan 2008 21:34:28 -0800, George Sakkis wrote:
> I believe the "what is the fastest way" question for such small well-
> defined tasks is worth asking on its own, regardless of whether it makes
> a difference in the application (or even if there is no application to
> begin with). Just b
On Jan 22, 12:15 am, Paddy <[EMAIL PROTECTED]> wrote:
> On Jan 22, 3:20 am, Alan Isaac <[EMAIL PROTECTED]> wrote:> I want to generate
> sequential pairs from a list.
> <>
> > What is the fastest way? (Ignore the import time.)
>
> 1) How fast is the met
On Jan 22, 3:20 am, Alan Isaac <[EMAIL PROTECTED]> wrote:
> I want to generate sequential pairs from a list.
<>
> What is the fastest way? (Ignore the import time.)
1) How fast is the method you have?
2) How much faster does it need to be for your application?
3) Are their any ot
On Jan 21, 10:20 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
> I want to generate sequential pairs from a list.
> Here is a way::
>
> from itertools import izip, islice
> for x12 in izip(islice(x,0,None,2),islice(x,1,None,2)):
> print x12
>
> (Of cour
Alan Isaac <[EMAIL PROTECTED]> writes:
> (Of course the print statement is just illustrative.)
> What is the fastest way? (Ignore the import time.)
You have to try a bunch of different ways and time them. One
idea (untested):
def pairs(seq):
while True:
yield (seq.next(), s
I want to generate sequential pairs from a list.
Here is a way::
from itertools import izip, islice
for x12 in izip(islice(x,0,None,2),islice(x,1,None,2)):
print x12
(Of course the print statement is just illustrative.)
What is the fastest way? (Ignore the import time.)
Thanks
35 matches
Mail list logo