Re: Merging ordered lists

2008-06-03 Thread etal
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 =

Re: Merging ordered lists

2008-06-03 Thread etal
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

Re: Merging ordered lists

2008-06-02 Thread etal
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

Re: Merging ordered lists

2008-06-02 Thread etal
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(): >  

Merging ordered lists

2008-05-31 Thread etal
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