Comments (4)
object() < object()
raises an exception in Python3, but this works and is fast:
class CmpFalse(object): __eq__ = __lt__ = __gt__ = lambda s,o: False
import heapq
h = []
heapq.heappush(h, (0, CmpFalse(), ['x']))
heapq.heappush(h, (0, CmpFalse(), {1:2}))
print(heapq.heappop(h))
print(heapq.heappop(h))
That's likely too simple to warrant adding to boltons.queueutils
.
So, http://boltons.readthedocs.io/en/latest/queueutils.html should mention that task
must be hashable and then this issue is finished.
from boltons.
Would float('nan') behave the same as your CmpFalse()?
Given that:
>>> float('nan')==float('nan')
False
>>> float('nan')<float('nan')
False
>>> float('nan')>float('nan')
False
from boltons.
heapq won't work either, because if I store tuples
(-priority, item)
, I can get comparisons between dicts if priorities match.
Just a note: As a workaround, it's possible put something that will always compare to False in between:
(-priority, object(), item)
The overhead should be manageable in many cases; even unpacking a 3-tuple vs. a 2-tuple in a single assignment seems to take almost the same (very short) time.
from boltons.
Docs updated, but I would like to think some more about this. I'm not sure there's a way to update priority without a uniqueness constraint, thus one of the original features would be defeated. That said, it has come up in discussion that someone may need a priority queue for non-unique items, but I haven't had any need over the years :)
I'm definitely fine with adding more simple queues, as long as their use case is clear! :)
from boltons.
Related Issues (20)
- Function to format a list with commas and a final 'and'/'or'
- attrs/dataclasses-style decorator helper
- Mfnvhudhvsdmbc HOT 1
- Test failure with Python 3.11 HOT 1
- Tag for the 23.0.0 release is missing HOT 1
- Include tests in future pypi sdist tarball HOT 5
- Convert list of dict items to list of string items
- `ParsedException.from_string(text).to_string() == text` property violated due to anchors
- `boltons.ecoutils` `23.0.0` breaks `pdb` interactive prompt in `pytest` debug sessions HOT 4
- Non-empty `dictutils.OMD` cannot be loaded from `pickle` HOT 1
- RFC: Make boltons Python 3.7+ only. HOT 8
- Support in-place union for `dictutils.OrderedMultiDict` HOT 1
- [Feature request] Parametrize the delimiter to make glom use any kind of Path delimiter, not just `.` HOT 1
- wraps loses keywords
- chunked filter HOT 3
- tracking some ideas HOT 3
- LRU .values() and dict return old entries HOT 3
- call _orig_default identity
- Names in `boltons.strutils.__all__` with no definitions
- Missing git tags for 23.1.0 & 23.1.1 releases HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boltons.