Closed fmark closed 14 years ago
Currently you can concatenate them using | or |=, which sortedlist inherits from the MutableSet abstract base class. I admit that's not very intuitive.
I worry that .extend() may sound like it will add things on at the end (when in fact each item will be inserted in the correct spot), and .union() may sound like duplicates will not be added (but they will be). How do you feel?
By the way, I should be able to address the issues you've been raising and push out a new version sometime within the next week at the latest.
Yet again, I didn't find the |= operator. Maybe all that is need is some better documentation.
I agree about the implied semantics of "union()" and "extend()". If you do add it as function, perhaps a name like "merge()" or "combine()" might be appropriate.
Yes, I've been putting off documentation for much too long. I'll get on that (opened as Issue #21). I'll also pour over the methods for list and set and make sure sortedlist has all the methods one might expect it to (Issue #20).
Awesome :) Thanks for the great module by the way!
Other options for a name include "update" and "add_all". "add_all" is probably the clearest. "update" is the name used by sortedlist's third cousin collections.Counter (2.7+).
"update" is also used by dict and set, but the handling of duplicate items is quite different from sortedlist's. "add_all" is a good suggestion. I'm leaning toward that.
Right, I appealed to Counter because it is very similar to sortedlist in that they are both sort of bags. I wonder to an extent if PriorityDeque or SortedBag wouldn't have been more telling—if not less obvious—names for sortedlist. sortedlist does implement the Sequence API, though I do sort of wonder why; has this been useful?
Good pointer about Counter. I couldn't remember if it's update method added or replaced, but I see now that it adds. In that case, I'm leaning toward "update". ;-)
Oh, and to answer your question: yes, the Sequence API has been useful (to me, at any rate). I rely pretty heavily on the ability to take an arbitrary slice.
As far as I can tell, there is no way to concatenate two sortedlist's. Neither the list style extend() nor the set style union() are present.