Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60749
| References | <b5e67d65-76a4-4a1a-87b4-70402c9bf865@googlegroups.com> |
|---|---|
| Date | 2013-11-29 13:03 +1100 |
| Subject | Re: how to implement a queue-like container with sort function |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3389.1385690583.18130.python-list@python.org> (permalink) |
On Fri, Nov 29, 2013 at 12:54 PM, iMath <redstone-cold@163.com> wrote:
> the container is similar to queue ,but queue doesn't have a sort function
It's either a queue that can be sorted, or a list with a length limit.
You could fairly easily implement either, because in Python, anything
can be subclassed. But I think possibly the easiest way is to simply
turn your queue into a list when you want to work with it:
>>> import queue
>>> a=queue.Queue(10)
>>> a.put("asdf")
>>> a.put("qwer")
>>> a.put("zxcv")
>>> a.put("1234")
>>> sorted(a.queue)
['1234', 'asdf', 'qwer', 'zxcv']
Though I don't know if this is what you meant. Putting too much onto a
queue.Queue will block. Were you wanting it, instead, to discard
entries? If so, which?
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to implement a queue-like container with sort function iMath <redstone-cold@163.com> - 2013-11-28 17:54 -0800
Re: how to implement a queue-like container with sort function Chris Angelico <rosuav@gmail.com> - 2013-11-29 13:03 +1100
Re: how to implement a queue-like container with sort function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-29 03:32 +0000
Re: how to implement a queue-like container with sort function iMath <redstone-cold@163.com> - 2013-11-28 18:04 -0800
Re: how to implement a queue-like container with sort function Chris Angelico <rosuav@gmail.com> - 2013-11-29 13:06 +1100
Re: how to implement a queue-like container with sort function iMath <redstone-cold@163.com> - 2013-11-28 18:32 -0800
Re: how to implement a queue-like container with sort function Cameron Simpson <cs@zip.com.au> - 2013-11-29 17:19 +1100
Re: how to implement a queue-like container with sort function MRAB <python@mrabarnett.plus.com> - 2013-11-29 02:23 +0000
Re: how to implement a queue-like container with sort function Terry Reedy <tjreedy@udel.edu> - 2013-11-28 21:31 -0500
Re: how to implement a queue-like container with sort function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-11-29 17:53 +1300
Re: how to implement a queue-like container with sort function iMath <redstone-cold@163.com> - 2013-11-29 04:33 -0800
Re: how to implement a queue-like container with sort function Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-29 14:57 +0000
Re: how to implement a queue-like container with sort function iMath <redstone-cold@163.com> - 2013-12-02 03:41 -0800
Re: how to implement a queue-like container with sort function Ned Batchelder <ned@nedbatchelder.com> - 2013-12-02 06:58 -0500
Re: how to implement a queue-like container with sort function Chris Angelico <rosuav@gmail.com> - 2013-12-02 23:04 +1100
Re: how to implement a queue-like container with sort function Ned Batchelder <ned@nedbatchelder.com> - 2013-12-02 07:26 -0500
csiph-web