Re: queue versus list

2020-03-20 Thread Antoon Pardon



Op 20/03/20 om 02:10 schreef Cameron Simpson:

On 20Mar2020 00:37, duncan smith  wrote:


Thread
safety is unimportant (for my purposes), but the docs at
https://docs.python.org/2/library/collections.html#collections.deque
state "Deques support thread-safe, memory efficient appends and pops
from either side of the deque with approximately the same O(1)
performance in either direction". Looking at the output from the
profiler for my implementation with the queue it looks like a deque is
being used but there's various other stuff happening relating to thread
safety. Is the lesson from this that if all you're doing is appending
and popping, then use a deque (rather than a queue) even if you want
thread safety? (It makes quite a difference in performance for my use
case.) Cheers.


A deque will change the ordering of the elements you process. Your 
list loop behaves in FIFO order, as does the queue. A dequeue (you 
you're doing a heappush and a heappop) will issue you the lowest 
current element on each iteration. If you merely need to process all 
the elements you're good. If the order matters you need to consider that.


A deque, being thread safe, will be using a lock. There will be a 
(quite small) overhead for that.



This doesn't seem correct. A deque is used to simulate a stack or a 
queue. It doesn't use heappush or heappop.


Antoon.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Reduce waiting queue at supermarket from Corona with Python-Webapp

2020-03-20 Thread Robin Becker

On 16/03/2020 17:38, Orges Leka wrote:

This would reduce the waiting queue at the supermarket and possibly the
contact to other people thus would help a little bit in slowing down the
spread of the Corona virus.
Unfortunately, I suspect nothing will alter the number of people in queues in British supermarkets. I am an older person 
and am probably a bit old-fashioned. I have been shocked at the way people are rushing the shops.


Late this week main shops announced first hour would be reserved for us oldies. That hasn't worked with scuffles and the 
elderly being pushed aside etc etc.


Women and children first is long gone the new British attitude is devil take 
the hindmost :)
--
Robin Becker
--
https://mail.python.org/mailman/listinfo/python-list


Re: Reduce waiting queue at supermarket from Corona with Python-Webapp

2020-03-20 Thread Orges Leka
Dear Robin,

I am sad to hear this. The same thing is / will happen(ing) in Germany I
suspect. But after the panic buys has gone, the supermarkets will leave
only a handful of people in, as it is happening in Italy. The app is meant
to inform others of those queues. But maybe it is just a silly idea. I am
not sure about it yet.

Kind regards,
Orges

Am Fr., 20. März 2020 um 12:22 Uhr schrieb Robin Becker :

> On 16/03/2020 17:38, Orges Leka wrote:
> > This would reduce the waiting queue at the supermarket and possibly the
> > contact to other people thus would help a little bit in slowing down the
> > spread of the Corona virus.
> Unfortunately, I suspect nothing will alter the number of people in queues
> in British supermarkets. I am an older person
> and am probably a bit old-fashioned. I have been shocked at the way people
> are rushing the shops.
>
> Late this week main shops announced first hour would be reserved for us
> oldies. That hasn't worked with scuffles and the
> elderly being pushed aside etc etc.
>
> Women and children first is long gone the new British attitude is devil
> take the hindmost :)
> --
> Robin Becker
>


-- 
Mit freundlichen Grüßen
Herr Dipl. Math. Orges Leka

Mobil: 015751078391
Email: [email protected]
Holzheimerstraße 25
65549 Limburg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reduce waiting queue at supermarket from Corona with Python-Webapp

2020-03-20 Thread joseph pareti
>  the supermarkets will leave only a handful of people
better later than never :-)
meanwhile folks are staging idiotic things like (NOT EVEN 2 WEEKS AGO) a
leipzig vs. tottenhame match with FULL STADION, or bragging about their
social stupidities on facebook and co.

I always thought (and I am getting more convinced by the day) that
autoritarian rule is the way to go

Am Fr., 20. März 2020 um 12:39 Uhr schrieb Orges Leka :

> Dear Robin,
>
> I am sad to hear this. The same thing is / will happen(ing) in Germany I
> suspect. But after the panic buys has gone, the supermarkets will leave
> only a handful of people in, as it is happening in Italy. The app is meant
> to inform others of those queues. But maybe it is just a silly idea. I am
> not sure about it yet.
>
> Kind regards,
> Orges
>
> Am Fr., 20. März 2020 um 12:22 Uhr schrieb Robin Becker <
> [email protected]
> >:
>
> > On 16/03/2020 17:38, Orges Leka wrote:
> > > This would reduce the waiting queue at the supermarket and possibly the
> > > contact to other people thus would help a little bit in slowing down
> the
> > > spread of the Corona virus.
> > Unfortunately, I suspect nothing will alter the number of people in
> queues
> > in British supermarkets. I am an older person
> > and am probably a bit old-fashioned. I have been shocked at the way
> people
> > are rushing the shops.
> >
> > Late this week main shops announced first hour would be reserved for us
> > oldies. That hasn't worked with scuffles and the
> > elderly being pushed aside etc etc.
> >
> > Women and children first is long gone the new British attitude is devil
> > take the hindmost :)
> > --
> > Robin Becker
> >
>
>
> --
> Mit freundlichen Grüßen
> Herr Dipl. Math. Orges Leka
>
> Mobil: 015751078391
> Email: [email protected]
> Holzheimerstraße 25
> 65549 Limburg
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Regards,
Joseph Pareti - Artificial Intelligence consultant
Joseph Pareti's AI Consulting Services
https://www.joepareti54-ai.com/
cell +49 1520 1600 209
cell +39 339 797 0644
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: queue versus list

2020-03-20 Thread Dan Stromberg
On Thu, Mar 19, 2020 at 6:11 PM Cameron Simpson  wrote:

> >> 4. If it doesn't need to be thread-safe, why not try deques instead?
> >
> >Bingo. Performance is indistinguishable from that of the list.
>
> A deque is implement using a list.
>

Actually, I think a deque is a doubly linked list of python lists.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: queue versus list

2020-03-20 Thread Dan Sommers
On Fri, 20 Mar 2020 06:50:29 -0700
Dan Stromberg  wrote:

> On Thu, Mar 19, 2020 at 6:11 PM Cameron Simpson  wrote:
> 
> > >> 4. If it doesn't need to be thread-safe, why not try deques instead?
> > >
> > >Bingo. Performance is indistinguishable from that of the list.
> >
> > A deque is implement using a list.
> >
> 
> Actually, I think a deque is a doubly linked list of python lists.

According to the source¹:

Data for deque objects is stored in a doubly-linked list of fixed
length blocks.

[...]

Textbook implementations of doubly-linked lists store one datum per
link, but that gives them a 200% memory overhead (a prev and next
link for each datum) and it costs one malloc() call per data
element.  By using fixed-length blocks, the link to data ratio is
significantly improved and there are proportionally fewer calls to
malloc() and free().  The data blocks of consecutive pointers also
improve cache locality.

¹ 
https://github.com/python/cpython/blob/3.8/Modules/_collectionsmodule.c#L19-L78

Dan

-- 
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [EXTERNAL] A simple probabilistic model for COVID-19

2020-03-20 Thread Barraclough, Dominic (ext. 414) via Python-list
Hi Pierre,

I'm interested in your Lea project and notice it is in a mercurial repo on 
bitbucket, what are your plans for the repo given that bitbucket are dropping 
support for mercurial repos in the summer?

https://bitbucket.org/blog/sunsetting-mercurial-support-in-bitbucket
[https://rlmr51w5rw3n7zek1m7tizzg-wpengine.netdna-ssl.com/wp-content/uploads/2019/08/[email protected]]
Sunsetting Mercurial support in Bitbucket - 
Bitbucket
The version control software market has evolved a lot since Bitbucket began in 
2008. When we launched, centralized version control was the norm and we only 
supported Mercurial repos.
bitbucket.org


Dominic

From: [email protected] 
Sent: Thursday, March 19, 2020 4:11 PM
To: [email protected] 
Subject: [EXTERNAL] A simple probabilistic model for COVID-19

CAUTION:
This email originated from outside of QVI. Do not click links or open 
attachments unless you recognize the sender and are expecting to receive this 
content from them. If you suspect the email is not legitimate, please forward 
it as an attachment to [email protected] and delete it from your Inbox.


Hi!

I've created a Jupyter notebook that presents a simple probabilistic model
linking diseases (cold, flu, COVID-19) to symptoms (fever, cough):

http://mybinder.org/v2/gh/piedenis/lea_mini_tutorials/master?filepath=Lea_CO
VID19.ipynb

Assuming that this model is accurate (which is probably not!), it allows you
to answer questions like:

What is the probability of having COVID-19 in the occurrence
of fever but without cough?

This model is programmed in Python, using Lea, a package dedicated to
probabilistic programming (PP).

Note that the goal is to let you discover PP and Bayesian reasoning, not to
provide you usable/trustable figures (even if the calculations are plainly
correct).

Take care of you!

Pierre Denis



--
Python-announce-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-announce-list.python.org/

Support the Python Software Foundation:
http://www.python.org/psf/donations/
-- 
https://mail.python.org/mailman/listinfo/python-list


A simple probabilistic model for COVID-19

2020-03-20 Thread pie.denis
Hi!

I've created a Jupyter notebook that presents a simple probabilistic model
linking diseases (cold, flu, COVID-19) to symptoms (fever, cough):

http://mybinder.org/v2/gh/piedenis/lea_mini_tutorials/master?filepath=Lea_CO
VID19.ipynb

Assuming that this model is accurate (which is probably not!), it allows you
to answer questions like:

What is the probability of having COVID-19 in the occurrence
of fever but without cough?

This model is programmed in Python, using Lea, a package dedicated to
probabilistic programming (PP).

Note that the goal is to let you discover PP and Bayesian reasoning, not to
provide you usable/trustable figures (even if the calculations are plainly
correct).

Take care of you!

Pierre Denis

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: queue versus list

2020-03-20 Thread Barry



> On 20 Mar 2020, at 00:42, duncan smith  wrote:
> 
> Bingo. Performance is indistinguishable from that of the list. Thread
> safety is unimportant (for my purposes), but the docs at
> https://docs.python.org/2/library/collections.html#collections.deque
> state "Deques support thread-safe, memory efficient appends and pops
> from either side of the deque with approximately the same O(1)

I did a performance test of list vs sequel as a fifo that had 10k elements in 
them.
Then I timed insert elements at the tail and popping from the head.

Duque is 10x faster then list, rest run macOS python 3.8

Barry


-- 
https://mail.python.org/mailman/listinfo/python-list


datepicker fails to find firstweekday in calendar

2020-03-20 Thread Rich Shepard

I'm running Python3-3.8.2 on Slackware-14.2/x86_64 and I tried to run Miguel
Martinez Lopez's datepicker.py (version 1.0.7) before learning how I can use
it in my application. It fails to find the attribute in the imported
calendar module:

$ python3 datepicker.py 
Traceback (most recent call last):

  File "datepicker.py", line 53, in 
class Calendar(ttk.Frame):
  File "datepicker.py", line 57, in Calendar
def __init__(self, master=None, year=None, month=None,
firstweekday=calendar.MONDAY, locale=None, activebackground='#b1dcfb',
activeforeground='black', selectbackground='#003eff',
selectforeground='white', command=None, borderwidth=1, relief="solid",
on_click_month_button=None):
AttributeError: module 'calendar' has no attribute 'MONDAY'

(N.B. The above itiation is line wrapped here but not in the trace back.)

Line 53 starts the calendar class:

class Calendar(ttk.Frame):
datetime = calendar.datetime.datetime
timedelta = calendar.datetime.timedelta

def __init__(self, master=None, year=None, month=None,
firstweekday=calendar.MONDAY, locale=None, activebackground='#b1dcfb',
activeforeground='black', selectbackground='#003eff',
selectforeground='white', command=None, borderwidth=1, relief="solid",
on_click_month_button=None):

(N.B. Local line wrapping; in the code it's all on one line.)

Since calendar is built in to Python3-3.8.2 where do I look for the source
of the problem so I can fix it?

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: queue versus list

2020-03-20 Thread Cameron Simpson

On 20Mar2020 06:50, Dan Stromberg  wrote:

Actually, I think a deque is a doubly linked list of python lists.


On 20Mar2020 09:45, Antoon Pardon  wrote:
This doesn't seem correct. A deque is used to simulate a stack or a 
queue. It doesn't use heappush or heappop.


You are both correct; brain fade on my part. I do not know why I 
conflated a deque with a heap.


Apologies for the confusion.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: datepicker fails to find firstweekday in calendar

2020-03-20 Thread MRAB

On 2020-03-20 22:43, Rich Shepard wrote:

I'm running Python3-3.8.2 on Slackware-14.2/x86_64 and I tried to run Miguel
Martinez Lopez's datepicker.py (version 1.0.7) before learning how I can use
it in my application. It fails to find the attribute in the imported
calendar module:

$ python3 datepicker.py
Traceback (most recent call last):
File "datepicker.py", line 53, in 
  class Calendar(ttk.Frame):
File "datepicker.py", line 57, in Calendar
  def __init__(self, master=None, year=None, month=None,
firstweekday=calendar.MONDAY, locale=None, activebackground='#b1dcfb',
activeforeground='black', selectbackground='#003eff',
selectforeground='white', command=None, borderwidth=1, relief="solid",
on_click_month_button=None):
AttributeError: module 'calendar' has no attribute 'MONDAY'

(N.B. The above itiation is line wrapped here but not in the trace back.)

Line 53 starts the calendar class:

class Calendar(ttk.Frame):
  datetime = calendar.datetime.datetime
  timedelta = calendar.datetime.timedelta

  def __init__(self, master=None, year=None, month=None,
firstweekday=calendar.MONDAY, locale=None, activebackground='#b1dcfb',
activeforeground='black', selectbackground='#003eff',
selectforeground='white', command=None, borderwidth=1, relief="solid",
on_click_month_button=None):

(N.B. Local line wrapping; in the code it's all on one line.)

Since calendar is built in to Python3-3.8.2 where do I look for the source
of the problem so I can fix it?


Is there another file called "calendar.py" somewhere?

Try putting "print(calendar.__file__)" after the import in the 
datepicker module.

--
https://mail.python.org/mailman/listinfo/python-list


Re: queue versus list

2020-03-20 Thread duncan smith
On 20/03/2020 21:57, Barry wrote:
> 
> 
>> On 20 Mar 2020, at 00:42, duncan smith  wrote:
>>
>> Bingo. Performance is indistinguishable from that of the list. Thread
>> safety is unimportant (for my purposes), but the docs at
>> https://docs.python.org/2/library/collections.html#collections.deque
>> state "Deques support thread-safe, memory efficient appends and pops
>> from either side of the deque with approximately the same O(1)
> 
> I did a performance test of list vs sequel as a fifo that had 10k elements in 
> them.
> Then I timed insert elements at the tail and popping from the head.
> 
> Duque is 10x faster then list, rest run macOS python 3.8
> 
> Barry
> 
> 

Yes, I avoided the cost of popping elements from the head by just
iterating over the list. So the timings came out very similar. But the
deque allows me to remove those elements efficiently. It's also neat
because it lets me switch from what is basically a breadth first search
of a graph to a depth first search by simply changing popleft() to
popright(). Cheers.

Duncan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datepicker fails to find firstweekday in calendar [FIXED]

2020-03-20 Thread Rich Shepard

On Sat, 21 Mar 2020, MRAB wrote:


Is there another file called "calendar.py" somewhere?


MRAB,

Mea culpa! There was a 'calendar.py' file I had downloaded in the past in
the same directory. I assumed that Python would use the built-in one before
the one in the directory. Removing that file solved the problem.

Try putting "print(calendar.__file__)" after the import in the datepicker 
module.


I did this prior to removing the existing calendar.py file and nothing but
the two previously reported errors displayed in the terminal. It didn't
point to the on-disk file.

I learned a valuable lesson.

Thanks very much,

Rich
--
https://mail.python.org/mailman/listinfo/python-list