On Jun 3, 1:22Â am, Peter Otten <[EMAIL PROTECTED]> wrote:
>
> Yes :)
>
> Seriously, you are using O(n) containers and O(n) lookup where mine uses
> O(1). For short lists it doesn't matter, but as the list length grows the
> difference gets huge:
>
> $ cat unique.py
> def unique(items):
> Â Â u =
On Jun 2, 11:08Â pm, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>
> If the inputs were not sorted, then I don't think you have a precise
> idea of what it means to merge them while preserving order. Â For
> example if the inputs are XYZPDQ and bYlmPz, then what does a merged
> sequence look like
On Jun 1, 12:34Â am, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>
> I would do it two steps. Â There's a number of ways to merge depending
> on whether everything is pulled into memory or
> not:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491285http://aspn.activestate.com/ASPN/Cookboo
On Jun 1, 1:49Â am, Peter Otten <[EMAIL PROTECTED]> wrote:
> Peter Otten wrote:
> > #untested
>
> Already found two major blunders :(
>
> # still untested
> import difflib
>
> def _merge(a, b):
> Â Â sm = difflib.SequenceMatcher(None, a, b)
> Â Â for op, a1, a2, b1, b2 in sm.get_opcodes():
> Â
Here's an algorithm question: How should I efficiently merge a
collection of mostly similar lists, with different lengths and
arbitrary contents, while eliminating duplicates and preserving order
as much as possible?
My code:
def merge_to_unique(sources):
"""Merge the unique elements from eac