[Baypiggies] a python puzzle
Jason Culverhouse
jason at mischievous.org
Wed Apr 14 18:24:24 CEST 2010
If the lists are already sorted wouldn't
sorted(itertools.chain(a,b))
be fairly efficient?
http://bugs.python.org/file4451/timsort.txt
Jason
On Apr 14, 2010, at 9:03 AM, Emile van Sebille wrote:
> a = [1, 1, 2, 4, 6, 8, 9]
> b = [1, 3, 4, 5, 6, 7, 8]
>
> def popwhile(l,t):
> r = []
> while l[:1] == t:
> r.append(l.pop(0))
> return r
>
> while bool(a or b):
> m = min(a[:1],b[:1]) or max(a[:1],b[:1])
> print popwhile(a,m), popwhile(b,m)
>
>
> Emile
>
> On 4/14/2010 8:20 AM Brent Pedersen said...
>> hi, in trying to write a func that does a kind of merging of 2 sorted lists,
>> i've come up with a fairly simple implementation that "almost works":
>> http://gist.github.com/365485
>>
>> but it hits StopIteration before returning the last value ([9], None)
>> i can wrap the whole thing in a bunch more if statements, i've tried
>> heapq.merge, but cant find a nice solution.
>>
>> any ideas? i think it's an interesting problem.
>> -brent
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>>
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
More information about the Baypiggies
mailing list