i am using below code merging two iterable , everything is good but some words which starts with Ö - Örnek, Ş - Şelale , İ-İstanbul, Ü - Ürgüp ... not sorted in correct place "ö" letter must come after "o", "ş" letter must come after 's'...
in result A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, Ç, İ, Ö, Ş , Ü .....
it must be A.C, Ç,... I, İ,....O, Ö,.... U, Ü,.....
sorry for my eng..
## {{{ http://code.activestate.com/recipes/491285/ (r3)
import heapq
def imerge(*iterables):
'''Merge multiple sorted inputs into a single sorted output.
Equivalent to: sorted(itertools.chain(*iterables))
>>> list(imerge([1,3,5,7], [0,2,4,8], [5,10,15,20], [], [25]))
[0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25]
'''
heappop, siftup, _StopIteration = heapq.heappop, heapq._siftup, StopIteration
h = []
h_append = h.append
for it in map(iter, iterables):
try:
next = it.next
h_append([next(), next])
except _StopIteration:
pass
heapq.heapify(h)
while 1:
try:
while 1:
v, next = s = h[0] # raises IndexError when h is empty
yield v
s[0] = next() # raises StopIteration when exhausted
siftup(h, 0) # restore heap condition
except _StopIteration:
heappop(h) # remove empty iterator
except IndexError:
return
if __name__ == '__main__':
import doctest
doctest.testmod()
## end of http://code.activestate.com/recipes/491285/ }}}