Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Raymond Hettinger
[Steve Howell] > Why wouldn't you get a competent C programmer simply make > list_ass_slice smart enough to make list.pop(0) O(1)? When this suggestion was discussed on python-dev years ago, it was rejected. One reason is that it was somewhat common for C code to access the list data structure di

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Steven D'Aprano
On Sat, 23 Jan 2010 14:10:10 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> The Box-Muller transform is reasonably simple, but you can't be serious >> that it is simpler than adding twelve random numbers and subtracting >> six! > > If you want a normal distribution, using the Box-Muller t

Re: this customize sort did not work ,what's wrong?

2010-01-23 Thread Stephen Hansen
On Sat, Jan 23, 2010 at 12:57 PM, thinke365 wrote: > def sort_by_list(E1, E2): >print len(E1), len(E2) >return len(list(E1)) > len(list(E2)) > > l.sort(cmp=sort_by_list) > The cmp function is defined as returning one of three values, -1, 0 and 1. You are returning true or false, so thin

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Roy Smith
In article , Terry Reedy wrote: > >> The page you should probably be looking at is > >> http://wiki.python.org/moin/TimeComplexity > > > > I was not aware of this page; thanks for pointing it out. > > Perhaps you could suggest on the tracker a place or places in the doc > where this relatively

Re: this customize sort did not work ,what's wrong?

2010-01-23 Thread Terry Reedy
On 1/23/2010 3:57 PM, thinke365 wrote: l = list() l1 = list((1, 2, 3, 4)) l2 = list((1,2)) l3 = list((1, 2, 3, 4, 5)) l.append(l1) l.append(l2) l.append(l3) print l def sort_by_list(E1, E2): print len(E1), len(E2) return len(list(E1))> len(list(E2)) l.sort(cmp=sort_by_list) print l

Re: how can i know if a python object have a attribute such as 'attr1'?

2010-01-23 Thread Terry Reedy
On 1/23/2010 10:56 AM, Arnaud Delobelle wrote: thinke365 writes: for example, i may define a python class: class A: def sayHello(): print 'hello' a = A() a.attr1 = 'hello' a.attr2 = 'bb' b = A() a.attr2 = 'aa' how can i know whether an object have an attribute named attr1?

Re: enumerated while loop

2010-01-23 Thread Terry Reedy
On 1/23/2010 9:44 AM, Roald de Vries wrote: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function like 'naturals' already exists, or a similar constr

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Terry Reedy
On 1/23/2010 2:02 PM, Roy Smith wrote: In article, Duncan Booth wrote: Roy Smith wrote: I'm looking at http://tinyurl.com/cdbwog. It shows all the operations of a list. What it does not show is their cost. For pop(), it has a note: "The pop() method is only supported by the list and a

Re: this customize sort did not work ,what's wrong?

2010-01-23 Thread MRAB
thinke365 wrote: jesus, now i fixed it, using odd lambda sort. l.sort(lambda x,y: cmp(len(x), len(y))) print l BUT I AM STILL CONFUSED WHY COSTOMIZED SORT FAILED TO SORT AS IT IS PROGRAMMER! thinke365 wrote: i mean the output i want is: [ [1, 2], [1, 2, 3, 4], [1, 2, 3, 4, 5]], that is sort

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Terry Reedy
On 1/23/2010 12:17 PM, Steve Howell wrote: Terry Reedy said: ''' If you try writing a full patch, as I believe someone did, or at least a prototype thereof, when the idea was discussed, you might have a better idea of what the tradeoffs are and why it was rejected. ''' I have to run, but tomor

ISO module for binomial coefficients, etc.

2010-01-23 Thread kj
Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm looking for something that can handle fairly large factorials (on the

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread Mr.M
MRAB ha scritto: I think you're right. I have rewritten my code, a piece at a time, and (and this is very annoying) now it works fine. I really can't understand what went wrong with my old code. Luca. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Paul Rubin
Steven D'Aprano writes: > The Box-Muller transform is reasonably simple, but you can't be serious > that it is simpler than adding twelve random numbers and subtracting six! If you want a normal distribution, using the Box-Muller transform is simpler because it spares you the complication of fig

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Steven D'Aprano
On Sat, 23 Jan 2010 12:29:22 -0800, Paul Rubin wrote: > Peter Chant writes: >> I remeber being told that adding up 12 random numbers in the range 0-1 >> (which is what most computer random number genertors at the time >> chucked out) and subtracted 6 gives a pretty good normal distribution. >> I

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Steven D'Aprano
On Sat, 23 Jan 2010 11:10:52 -0800, thinke365 wrote: > of course i have tried random package, but can this package generate > random sequence that satisfy possion distribution , normal distribution > and uniform distribution Please don't talk garbage. If you had really tried the random module, yo

Re: this customize sort did not work ,what's wrong?

2010-01-23 Thread Duncan Booth
thinke365 wrote: > jesus, now i fixed it, using odd lambda sort. > l.sort(lambda x,y: cmp(len(x), len(y))) > print l > > BUT I AM STILL CONFUSED WHY COSTOMIZED SORT FAILED TO SORT AS IT IS > PROGRAMMER! Try reading the documentation: >>> help(list.sort) Help on method_descriptor: sort(...)

Re: this customize sort did not work ,what's wrong?

2010-01-23 Thread Alf P. Steinbach
* thinke365: jesus, now i fixed it, using odd lambda sort. l.sort(lambda x,y: cmp(len(x), len(y))) print l This uses 'cmp'. Your earlier code, quoted below, used '>'. BUT I AM STILL CONFUSED WHY COSTOMIZED SORT FAILED TO SORT AS IT IS PROGRAMMER! Please don't shout. thinke365 wrote: i

Re: this customize sort did not work ,what's wrong?

2010-01-23 Thread thinke365
jesus, now i fixed it, using odd lambda sort. l.sort(lambda x,y: cmp(len(x), len(y))) print l BUT I AM STILL CONFUSED WHY COSTOMIZED SORT FAILED TO SORT AS IT IS PROGRAMMER! thinke365 wrote: > > i mean the output i want is: > [ [1, 2], [1, 2, 3, 4], [1, 2, 3, 4, 5]], that is sort according to

Re: this customize sort did not work ,what's wrong?

2010-01-23 Thread thinke365
i mean the output i want is: [ [1, 2], [1, 2, 3, 4], [1, 2, 3, 4, 5]], that is sort according to the length of the list element thinke365 wrote: > > l = list() > l1 = list((1, 2, 3, 4)) > l2 = list((1,2)) > l3 = list((1, 2, 3, 4, 5)) > l.append(l1) > l.append(l2) > l.append(l3) > print l > > de

this customize sort did not work ,what's wrong?

2010-01-23 Thread thinke365
l = list() l1 = list((1, 2, 3, 4)) l2 = list((1,2)) l3 = list((1, 2, 3, 4, 5)) l.append(l1) l.append(l2) l.append(l3) print l def sort_by_list(E1, E2): print len(E1), len(E2) return len(list(E1)) > len(list(E2)) l.sort(cmp=sort_by_list) print l output: [[1, 2, 3, 4], [1, 2], [1, 2, 3, 4

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Paul Rubin
Peter Chant writes: > I remeber being told that adding up 12 random numbers in the range 0-1 > (which is what most computer random number genertors at the time chucked > out) and subtracted 6 gives a pretty good normal distribution. I think I > did try it once and it failed, but I must have do

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Paul Rubin
thinke365 writes: > of course i have tried random package, but can this package generate random > sequence that satisfy possion distribution , normal distribution and uniform > distribution Did you look at the documentation? -- http://mail.python.org/mailman/listinfo/python-list

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Arnaud Delobelle
thinke365 writes: > such as uniform distribution, Normal distribution or poisson distribution. > is there any package that can be used to generate such random numbers. It's all in the standard library, the module is called -surprisingly- 'random'. - use random.uniform for the uniform distributi

Re: installing psycopg2-2.0.13 with python3.1

2010-01-23 Thread Sibylle Koczian
Iain Barnett schrieb: On 21 Jan 2010, at 00:11, Gabriel Genellina wrote: If you insist on using Python 3.1, there is another interface to PostgreSQL called pg8000 that claims to be Python 3.x compatible (I've not actually tested it). [1] http://mail.python.org/pipermail/python-porting/2008-D

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Peter Chant
thinke365 wrote: > > such as uniform distribution, Normal distribution or poisson distribution. > is there any package that can be used to generate such random numbers. > I remeber being told that adding up 12 random numbers in the range 0-1 (which is what most computer random number genertors

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread MRAB
Mr.M wrote: MRAB ha scritto: Did you specify that the method accepts keywords arguments with METH_KEYWORDS? The function would take parameters for the instance (self), the positional arguments (args) and the keyword arguments (kwargs). http://docs.python.org/c-api/structures.html If you don't

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread thinke365
Bugzilla from ra.ravi@gmail.com wrote: > > On Jan 23, 10:37 pm, thinke365 wrote: >> such as uniform distribution, Normal distribution or poisson >> distribution. >> is there any package that can be used to generate such random numbers. >> >> -- >> View this message in >> context:http://old

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Roy Smith
In article , Duncan Booth wrote: > Roy Smith wrote: > > > I'm looking at http://tinyurl.com/cdbwog. It shows all the operations > > of a list. What it does not show is their cost. For pop(), it has a > > note: > > > > "The pop() method is only supported by the list and array types. The >

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Ravi
On Jan 23, 10:37 pm, thinke365 wrote: > such as uniform distribution, Normal distribution or poisson distribution. > is there any package that can be used to generate such random numbers. > > -- > View this message in > context:http://old.nabble.com/how-to-generate-random-numbers-that-satisfy-cer

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Aahz
In article <8e4d3fe2-c4bd-4a73-9c50-7a336dab2...@o28g2000yqh.googlegroups.com>, Steve Howell wrote: >On Jan 22, 11:10=A0pm, a...@pythoncraft.com (Aahz) wrote: >> >>>I know Python's number one concern will never be speed, but if Python >>>makes an O(1) operation into an unnecessarily O(N) operatio

Re: ISC License

2010-01-23 Thread Aahz
In article <00eb248d-c9c9-430f-bc83-41ac865c5...@e11g2000yqe.googlegroups.com>, Joan Miller wrote: > >There is a license approved by the OSI, the ISC License [1], which >should be included in the PyPi classifiers [2]. > >[1] https://www.isc.org/software/license >http://www.opensource.org/licenses

counting character occurrences

2010-01-23 Thread Wilbert Berendsen
Op vrijdag 22 januari 2010 schreef Arnaud: > Why not just start with (untested): > > import codecs > from collections import defaultdict > > tcounters = defaultdict(int) > f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") > > for c in f.read(): > tcounters[c] += 1 > > f

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread Mr.M
MRAB ha scritto: Did you specify that the method accepts keywords arguments with METH_KEYWORDS? The function would take parameters for the instance (self), the positional arguments (args) and the keyword arguments (kwargs). http://docs.python.org/c-api/structures.html If you don't use METH_KEY

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread MRAB
Mr.M wrote: Carl Banks ha scritto: (some declarations omitted here) You probably shouldn't have, that could be where the error is I'd include the whole function up to the call that raises the exception. Thank you so much Carl for your help, i'll provide more info so that you can try to

Re: iterating lists

2010-01-23 Thread Steven D'Aprano
On Sat, 23 Jan 2010 18:29:33 +0100, Roel Schroeven wrote: >> for w in l1[:]: #use copy of l1 for iteration >> print(l1.pop()) #decomposite list > > I would prefer: > > while l1: > print(l1.pop()) I would prefer: for x in reversed(l1): print(x) l1[:] = [] And garbage dispose of

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 7:54 am, Steven D'Aprano wrote: > On Sat, 23 Jan 2010 09:57:04 -0500, Roy Smith wrote: > > In article , > >  "Alf P. Steinbach" wrote: > > >> But it would IMHO have been better if it wasn't called "list", which > >> brings in the wrong associations for someone used to other languages.

how to generate random numbers that satisfy certain distribution

2010-01-23 Thread thinke365
such as uniform distribution, Normal distribution or poisson distribution. is there any package that can be used to generate such random numbers. -- View this message in context: http://old.nabble.com/how-to-generate-random-numbers-that-satisfy-certain-distribution-tp27288180p27288180.html Sent

Re: iterating lists

2010-01-23 Thread Stefan Behnel
ceciliasei...@gmx.de, 23.01.2010 17:29: > Arnaud Delobelle wrote: >> ceciliasei...@gmx.de writes: >> >>> As you were talking about list.pop()... >>> >>> Is anyone able to reproduce the following and explain why this happens >>> by chance? (Using 3.1.1) >>> >>> l1 = ["ready", "steady", "go"] >>> l2

Re: iterating lists

2010-01-23 Thread Roel Schroeven
Op 2010-01-23 17:29, ceciliasei...@gmx.de schreef: > > > Arnaud Delobelle schrieb: >> ceciliasei...@gmx.de writes: >> >>> As you were talking about list.pop()... >>> >>> Is anyone able to reproduce the following and explain why this happens >>> by chance? (Using 3.1.1) >>> >>> l1 = ["ready", "ste

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 4:12 am, Steven D'Aprano wrote: > On Fri, 22 Jan 2010 21:42:43 -0800, Steve Howell wrote: > > This innocent program here literally moves about a million bytes of > > memory around for no good reason: > > >     lst = [] > >     for i in range(2000): > >         lst.append(i) > >     whil

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 4:12 am, Steven D'Aprano wrote: > > > An alternative would be to do exactly what you want lists to do: track > the start of the list. Untested: > >     def recurse(prefix_lines): >         start = 0 >         end = len(prefix_lines) >         while start < end: >             prefix, lin

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 6:40 am, Roy Smith wrote: > In article > , >  Steve Howell wrote: > > > This innocent program here literally moves about a million bytes of > > memory around for no good reason: > > >     lst = [] > >     for i in range(2000): > >         lst.append(i) > >     while lst: > >         pr

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 5:46 am, Christian Heimes wrote: > Steve Howell wrote: > > Another benchmark is that deques are slower than lists for accessing > > elements. > > deques are optimized for accessing, inserting and removing data from > both ends. For anything else it's slower than the list type. The fact

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Alf P. Steinbach
* Steven D'Aprano: On Sat, 23 Jan 2010 09:57:04 -0500, Roy Smith wrote: In article , "Alf P. Steinbach" wrote: But it would IMHO have been better if it wasn't called "list", which brings in the wrong associations for someone used to other languages. +1. When I first started using Python (

Re: py2exe deal with python command line inside a program

2010-01-23 Thread im_smialing
On Jan 22, 2:35 pm, susan_kij...@yahoo.ca wrote: > Hi, > > I need to create a python subprogress, like this: > myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], >                                        env=env, stdin=subprocess.PIPE, >                                        stdout=su

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Duncan Booth
Roy Smith wrote: > I'm looking at http://tinyurl.com/cdbwog. It shows all the operations > of a list. What it does not show is their cost. For pop(), it has a > note: > > "The pop() method is only supported by the list and array types. The > optional argument i defaults to -1, so that by de

Re: Re: iterating lists

2010-01-23 Thread ceciliaseidel
Arnaud Delobelle schrieb: ceciliasei...@gmx.de writes: As you were talking about list.pop()... Is anyone able to reproduce the following and explain why this happens by chance? (Using 3.1.1) l1 = ["ready", "steady", "go"] l2 = ["one", "two", "tree"] l3 = ["lift off"] for w in l1: Ouch...

Re: A.x vs. A["x"]

2010-01-23 Thread Steve Holden
Martin Drautzburg wrote: > Terry Reedy wrote: > >> On 1/22/2010 2:29 PM, Martin Drautzburg wrote: >>> This has probably been asekd a million times, but if someone could >>> give a short answer anyways I's be most grateful. >>> >>> What is it that allows one to write A.x? If I have a variable A, >

Re: how can i know if a python object have a attribute such as 'attr1'?

2010-01-23 Thread Arnaud Delobelle
thinke365 writes: > for example, i may define a python class: > class A: > def sayHello(): > print 'hello' > > a = A() > a.attr1 = 'hello' > a.attr2 = 'bb' > > b = A() > a.attr2 = 'aa' > > how can i know whether an object have an attribute named attr1? hasattr(a, 'attr1') -- Arn

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steven D'Aprano
On Sat, 23 Jan 2010 09:57:04 -0500, Roy Smith wrote: > In article , > "Alf P. Steinbach" wrote: > >> But it would IMHO have been better if it wasn't called "list", which >> brings in the wrong associations for someone used to other languages. > > +1. > > When I first started using Python (bac

how can i know if a python object have a attribute such as 'attr1'?

2010-01-23 Thread thinke365
for example, i may define a python class: class A: def sayHello(): print 'hello' a = A() a.attr1 = 'hello' a.attr2 = 'bb' b = A() a.attr2 = 'aa' how can i know whether an object have an attribute named attr1? -- View this message in context: http://old.nabble.com/how-can-i-kno

Re: iterating lists

2010-01-23 Thread Alf P. Steinbach
* ceciliasei...@gmx.de: As you were talking about list.pop()... Is anyone able to reproduce the following and explain why this happens by chance? (Using 3.1.1) l1 = ["ready", "steady", "go"] l2 = ["one", "two", "tree"] l3 = ["lift off"] for w in l1: print(l1.pop()) #prints only "go stead

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:58 PM, Mark Dickinson wrote: On Jan 23, 2:44 pm, Roald de Vries wrote: I assume a function like 'naturals' already exists, or a similar construction for the same purpose. But what is it called? itertools.count() On Jan 23, 2010, at 4:04 PM, Jan Kaliszewski wrote:

Re: iterating lists

2010-01-23 Thread Arnaud Delobelle
ceciliasei...@gmx.de writes: > As you were talking about list.pop()... > > Is anyone able to reproduce the following and explain why this happens > by chance? (Using 3.1.1) > > l1 = ["ready", "steady", "go"] > l2 = ["one", "two", "tree"] > l3 = ["lift off"] > > for w in l1: >print(l1.pop()) #

iterating lists

2010-01-23 Thread ceciliaseidel
As you were talking about list.pop()... Is anyone able to reproduce the following and explain why this happens by chance? (Using 3.1.1) l1 = ["ready", "steady", "go"] l2 = ["one", "two", "tree"] l3 = ["lift off"] for w in l1: print(l1.pop()) #prints only "go steady" - why not "ready"?? f

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:49 PM, Diez B. Roggisch wrote: Am 23.01.10 15:44, schrieb Roald de Vries: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a fu

Re: enumerated while loop

2010-01-23 Thread Roald de Vries
On Jan 23, 2010, at 3:50 PM, Grant Edwards wrote: On 2010-01-23, Roald de Vries wrote: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I

Re: enumerated while loop

2010-01-23 Thread Jan Kaliszewski
23-01-2010 o 15:49:23 Diez B. Roggisch wrote: Am 23.01.10 15:44, schrieb Roald de Vries: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function lik

Re: enumerated while loop

2010-01-23 Thread Mark Dickinson
On Jan 23, 2:44 pm, Roald de Vries wrote: > I assume a function like 'naturals' already exists, or a similar   > construction for the same purpose. But what is it called? itertools.count() -- Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Roy Smith
In article , "Alf P. Steinbach" wrote: > But it would IMHO have been better if it wasn't called "list", which brings > in the wrong associations for someone used to other languages. +1. When I first started using Python (back in the 1.4 days), I assumed a list was a singly-linked list. Whic

Re: medians for degree measurements

2010-01-23 Thread Arnaud Delobelle
Steve Howell writes: > I just saw the thread for medians, and it reminded me of a problem > that I need to solve. We are writing some Python software for > sailing, and we need to detect when we've departed from the median > heading on the leg. Calculating arithmetic medians is > straightforwar

Re: enumerated while loop

2010-01-23 Thread Grant Edwards
On 2010-01-23, Roald de Vries wrote: > Dear all, > > I sometimes want to use an infinite while loop with access to the loop > index, like this: > > def naturals(): > i = 0 > while True: > yield i > y += 1 > > for i in naturals(): > print(i) > > I assume a function like '

Re: enumerated while loop

2010-01-23 Thread Diez B. Roggisch
Am 23.01.10 15:44, schrieb Roald de Vries: Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function like 'naturals' already exists, or a similar constru

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Roy Smith
In article , Steve Howell wrote: > This innocent program here literally moves about a million bytes of > memory around for no good reason: > > lst = [] > for i in range(2000): > lst.append(i) > while lst: > print lst.pop(0) > > Why? Because list.pop(0) is implemen

enumerated while loop

2010-01-23 Thread Roald de Vries
Dear all, I sometimes want to use an infinite while loop with access to the loop index, like this: def naturals(): i = 0 while True: yield i y += 1 for i in naturals(): print(i) I assume a function like 'naturals' already exists, or a similar construction for the same

Re: Consume an iterable

2010-01-23 Thread Peter Otten
Muhammad Alkarouri wrote: > On 23 Jan, 13:46, Peter Otten <__pete...@web.de> wrote: >> def consume_islice(n, items): >> next(islice(items, n, n), None) > I submitted the bug report before considering this alternative, which > is better. I may add this later in the day, but I have to wait a >

Re: Consume an iterable

2010-01-23 Thread Muhammad Alkarouri
On 23 Jan, 13:46, Peter Otten <__pete...@web.de> wrote: > Peter Otten wrote: > > Duncan Booth wrote: > > >> Peter Otten <__pete...@web.de> wrote: > > >>> With next(islice(...), None) I seem to have found a variant that beats > >>> both  competitors. > > >> It has different behaviour for n==0 but I'

Re: Consume an iterable

2010-01-23 Thread Muhammad Alkarouri
On 23 Jan, 13:32, Peter Otten <__pete...@web.de> wrote: > Muhammad Alkarouri wrote: > > The next function performs much better. It is also much more direct > > for the purposes of consume and much more understandable (at least for > > me) as it doesn't require a specialized data structure which is

Re: Consume an iterable

2010-01-23 Thread Peter Otten
Peter Otten wrote: > Duncan Booth wrote: > >> Peter Otten <__pete...@web.de> wrote: >> >>> With next(islice(...), None) I seem to have found a variant that beats >>> both competitors. >>> >> It has different behaviour for n==0 but I'm sure that's easily fixed. > > "Different behaviour" being

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Christian Heimes
Steve Howell wrote: > Another benchmark is that deques are slower than lists for accessing > elements. deques are optimized for accessing, inserting and removing data from both ends. For anything else it's slower than the list type. The fact was explained in this very thread yesterday. Christian

Re: Consume an iterable

2010-01-23 Thread Peter Otten
Muhammad Alkarouri wrote: > The next function performs much better. It is also much more direct > for the purposes of consume and much more understandable (at least for > me) as it doesn't require a specialized data structure which is > subsequently not used as such. > I am thus inclined to report

Re: Consume an iterable

2010-01-23 Thread Peter Otten
Duncan Booth wrote: > Peter Otten <__pete...@web.de> wrote: > >> With next(islice(...), None) I seem to have found a variant that beats >> both competitors. >> > It has different behaviour for n==0 but I'm sure that's easily fixed. "Different behaviour" being a euphemism for broken ;) def con

Re: Consume an iterable

2010-01-23 Thread Peter Otten
Duncan Booth wrote: > Peter Otten <__pete...@web.de> wrote: > >> With next(islice(...), None) I seem to have found a variant that beats >> both competitors. >> > It has different behaviour for n==0 but I'm sure that's easily fixed. "Different behaviour" being a euphemism for broken ;) def con

Re: Consume an iterable

2010-01-23 Thread Muhammad Alkarouri
On 23 Jan, 12:45, Peter Otten <__pete...@web.de> wrote: > Muhammad Alkarouri wrote: > > Thanks everyone, but not on my machine (Python 2.6.1, OS X 10.6) it's > > not: > > > In [1]: from itertools import count, islice > > > In [2]: from collections import deque > > > In [3]: i1=count() > > > In [4]:

Re: Consume an iterable

2010-01-23 Thread Duncan Booth
Peter Otten <__pete...@web.de> wrote: > With next(islice(...), None) I seem to have found a variant that beats > both competitors. > It has different behaviour for n==0 but I'm sure that's easily fixed. -- http://mail.python.org/mailman/listinfo/python-list

Re: Consume an iterable

2010-01-23 Thread Peter Otten
Muhammad Alkarouri wrote: > Thanks everyone, but not on my machine (Python 2.6.1, OS X 10.6) it's > not: > > > In [1]: from itertools import count, islice > > In [2]: from collections import deque > > In [3]: i1=count() > > In [4]: def consume1(iterator, n): >...: deque(islice(iterato

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Arnaud Delobelle
Dave Angel writes: > Arnaud Delobelle wrote: >> Steve Howell writes: >> >> >>> On Jan 22, 12:14 pm, Chris Rebert wrote: >>> >> I made the comment you quoted. In CPython, it is O(n) to delete/insert >> an element at the start of the list - I know it because I looked at the >> implementa

Re: A.x vs. A["x"]

2010-01-23 Thread Martin Drautzburg
Terry Reedy wrote: > On 1/22/2010 2:29 PM, Martin Drautzburg wrote: >> This has probably been asekd a million times, but if someone could >> give a short answer anyways I's be most grateful. >> >> What is it that allows one to write A.x? If I have a variable A, >> I know you can do this with cl

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steven D'Aprano
On Fri, 22 Jan 2010 21:42:43 -0800, Steve Howell wrote: > This innocent program here literally moves about a million bytes of > memory around for no good reason: > > lst = [] > for i in range(2000): > lst.append(i) > while lst: > print lst.pop(0) > > Why? Because lis

Re: medians for degree measurements

2010-01-23 Thread Steven D'Aprano
On Fri, 22 Jan 2010 22:09:54 -0800, Steve Howell wrote: > On Jan 22, 5:12 pm, MRAB wrote: >> Steve Howell wrote: >> > I just saw the thread for medians, and it reminded me of a problem >> > that I need to solve.  We are writing some Python software for >> > sailing, and we need to detect when we'

Re: Using dictionary key as a regular expression class

2010-01-23 Thread Steve Holden
Chris Jones wrote: > On Fri, Jan 22, 2010 at 05:07:13PM EST, Arnaud Delobelle wrote: > > [..] > >> import codecs >> from collections import defaultdict >> >> tcounters = defaultdict(int) >> f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") >> >> for c in f.read(): >> tcoun

Re: Mastering Python 3 I/O - Special Preview - Feb 5, 2010 (Chicago)

2010-01-23 Thread Steve Holden
Chris Colbert wrote: > oops :) > Yes, but only a little oops. I think it's probably fairly well-known that David Beazley and I both supply training, and you'd hardly expect profit to be off the list of objectives for US trainers. But my failure to hit "reply to sender only" certainly did show that

Re: Consume an iterable

2010-01-23 Thread Muhammad Alkarouri
Thanks everyone, but not on my machine (Python 2.6.1, OS X 10.6) it's not: In [1]: from itertools import count, islice In [2]: from collections import deque In [3]: i1=count() In [4]: def consume1(iterator, n): ...: deque(islice(iterator, n), maxlen=0) ...: ...: In [5]: i2=count(

ISC License

2010-01-23 Thread Joan Miller
There is a license approved by the OSI, the ISC License [1], which should be included in the PyPi classifiers [2]. [1] https://www.isc.org/software/license http://www.opensource.org/licenses/isc-license.txt [2] http://pypi.python.org/pypi?%3Aaction=list_classifiers -- http://mail.python.org/mail

Re: counting lines of code

2010-01-23 Thread Michele Simionato
On Jan 22, 10:30 pm, Steve Holden wrote: > >> Oh, sorry, did I have the wrong opinion? > > > You had a condescending attitude. > > Towards someone who is fairly obviously not a Python neophyte. > > Please don't think we are telling you you can't have any opinion you > like. Just don't expect to ge

Re: counting lines of code

2010-01-23 Thread Michele Simionato
On Jan 22, 7:51 pm, Phlip wrote: > On Jan 21, 9:00 pm, Michele Simionato > wrote: > > > Just for fun I have run cloc on our trunk: > > > SUM:                8743    272238    215871   1470139 x   1.84 = > > 2708354.95 > > Nice! > > My favorite version of a cloc system can distinguish test from >

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 1:24 am, Terry Reedy wrote: > On 1/23/2010 3:23 AM, Steve Howell wrote: > > > On Jan 23, 12:13 am, Terry Reedy  wrote: > > >> Challenge yes, mock no. > > >> Part of writing good basic data structures is not adding needless > >> complication from featuritis and not penalizing 99.99% of a

Re: Efficient Running Median

2010-01-23 Thread Bearophile
Very nice. I have added a comment at the bottom, using a circular queue instead of a deque may be faster. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread Mr.M
Carl Banks ha scritto: (some declarations omitted here) You probably shouldn't have, that could be where the error is I'd include the whole function up to the call that raises the exception. Thank you so much Carl for your help, i'll provide more info so that you can try to fix my errors

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Alf P. Steinbach
* Steve Howell: On Jan 23, 12:32 am, "Alf P. Steinbach" wrote: * Steve Howell: On Jan 23, 12:13 am, Terry Reedy wrote: Challenge yes, mock no. Part of writing good basic data structures is not adding needless complication from featuritis and not penalizing 99.99% of access to satify a .01%

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 12:13 am, Terry Reedy wrote: > On 1/23/2010 12:58 AM, Steve Howell wrote: > > > I really want to use list *normally* with all its perfectly good > > semantics and reasonable implementation, except for its blind spot > > with respect to popping the first element off the list. > > It was

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Terry Reedy
On 1/23/2010 3:23 AM, Steve Howell wrote: On Jan 23, 12:13 am, Terry Reedy wrote: Challenge yes, mock no. Part of writing good basic data structures is not adding needless complication from featuritis and not penalizing 99.99% of access to satify a .01% need better satisfied another way. I

Re: Using dictionary key as a regular expression class

2010-01-23 Thread Chris Jones
On Sat, Jan 23, 2010 at 02:45:41AM EST, Terry Reedy wrote: > On 1/22/2010 9:58 PM, Chris Jones wrote: >> Do you mean I should just read the file one character at a time? > > Whoops, my misdirection (you can .read(1), but this is s l o w. > I meant to suggest processing it a char at a time. R

www.phptutorial.me

2010-01-23 Thread groups_ads12
www.phptutorial.me php php help free php free php scripts

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 12:32 am, "Alf P. Steinbach" wrote: > * Steve Howell: > > > On Jan 23, 12:13 am, Terry Reedy wrote: > >> Challenge yes, mock no. > > >> Part of writing good basic data structures is not adding needless > >> complication from featuritis and not penalizing 99.99% of access to > >> satify

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Alf P. Steinbach
* Steve Howell: On Jan 23, 12:13 am, Terry Reedy wrote: Challenge yes, mock no. Part of writing good basic data structures is not adding needless complication from featuritis and not penalizing 99.99% of access to satify a .01% need better satisfied another way. I would like to challenge yo

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 23, 12:13 am, Terry Reedy wrote: > > Challenge yes, mock no. > > Part of writing good basic data structures is not adding needless > complication from featuritis and not penalizing 99.99% of access to > satify a .01% need better satisfied another way. > I would like to challenge your asser

Re: medians for degree measurements

2010-01-23 Thread Terry Reedy
On 1/23/2010 1:09 AM, Steve Howell wrote: On Jan 22, 5:12 pm, MRAB wrote: I like this implementation, and it would probably work 99.% of the time for my particular use case. The only (very contrived) edge case that I can think of is when you have 10 bearings to SSW, 10 bearings to SSE, a

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Terry Reedy
On 1/23/2010 12:58 AM, Steve Howell wrote: I really want to use list *normally* with all its perfectly good semantics and reasonable implementation, except for its blind spot with respect to popping the first element off the list. It was not designed for that. .pop() was added to lists about 1

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Steve Howell
On Jan 22, 11:10 pm, a...@pythoncraft.com (Aahz) wrote: > In article <83082e19-9130-45a8-91f2-8601c1fda...@22g2000yqr.googlegroups.com>, > Steve Howell   wrote: > > > > > > >I really want to use list *normally* with all its perfectly good > >semantics and reasonable implementation, except for its b

  1   2   >