def ratio_merge(first_list, second_list, merge_ratio=0.5, desired_length=None):
    # This function acts as a generator producing elements from the two given lists by the given <merge_ratio>.
    # The generator would preserve any internal order within the lists and would produce no more then 
    # <desired_length> elements in total.
    # In case the total number of elements withing either the lists is not enough to maintain the desired ratio
    # throughout, the function would continue to generate elements from the remaining set until <desired_length> 
    # elements were produced.
    current_ratio = 0.0
    current_length = 0
    first_list_pop_count = 0
    second_list_pop_count = 0

    combined_list_length = len(first_list) + len(second_list)
    if desired_length is None or desired_length > combined_list_length:
        desired_length = combined_list_length

    try:
        while current_length < desired_length:
            if current_ratio <= merge_ratio:
                yield first_list[first_list_pop_count]
                first_list_pop_count += 1
            else:
                yield second_list[second_list_pop_count]
                second_list_pop_count += 1
            current_length += 1
            current_ratio = float(first_list_pop_count) / current_length

    except IndexError:
        lst, lst_count = (first_list, first_list_pop_count) if first_list_pop_count < len(first_list) else (second_list, second_list_pop_count)
        try:
            while current_length < desired_length:
                yield lst[lst_count]
                lst_count += 1
                current_length += 1

        except IndexError:
            return


def test_print(actual, expected):
    return 'PASS' if cmp(actual, expected)==0 else 'FAIL. \n Expected: {}\n Got:      {}'.format(expected, actual) 


def run_tests():
    from itertools import chain
    x = [1,2,3,4,5,6,7,8,9,0]
    y = ['a','b','c','d','e','f','g','h','i','j']
    print 'compare to zip (flattened) :', test_print(list(ratio_merge(x,y)),list(chain(*zip(x,y))))

    print '75:25 ratio (limited to 10):',  test_print(list(ratio_merge(x,y,0.75,10)), [1, 'a', 2, 3, 4, 'b', 5, 6, 7, 'c'])
    print '25:75 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.25,10)), [1, 'a', 'b', 'c', 2, 'd', 'e', 'f', 3, 'g'])
    print '70:30 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.7,10)), [1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7])
    print '30:70 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.3,10)), [1, 'a', 'b', 'c', 2, 'd', 'e', 3, 'f', 'g'])
    print '70:30 ratio (limited to 9):', test_print(list(ratio_merge(x,y,0.7,9)), [1, 'a', 2, 3, 'b', 4, 5, 'c', 6])
    print '70:30 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.7,10)), [1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7])
    print '70:30 ratio (limited to 11):', test_print(list(ratio_merge(x,y,0.7,11)), [1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7, 8])
    print '70:30 ratio (unlimited):', test_print(list(ratio_merge(x,y,0.7)), [1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7, 8, 'd', 9, 0, 'e', 'f', 'g', 'h', 'i', 'j'])
    print '70:30 ratio (unlimited, but only 3 elements in second list):', test_print(list(ratio_merge(x,y[:3],0.7)), [1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7, 8, 9, 0])
    print '70:30 ratio (unlimited, but only 3 elements in first list):', test_print(list(ratio_merge(x[:3],y,0.7)), [1, 'a', 2, 3, 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])
    print '70:30 ratio (limited to 10, but only 3 elements in first list):', test_print(list(ratio_merge(x[:3],y,0.7,10)), [1, 'a', 2, 3, 'b', 'c', 'd', 'e', 'f', 'g'])

run_tests()

@@ -70,19 +70,33 @@
 gth=None
+, strict=False
 ):%0A
-
     # Th
@@ -1100,18 +1100,71 @@
       el
-se
+if not strict or first_list_pop_count %3C len(first_list)
 :%0A      
@@ -1378,32 +1378,70 @@
 ept IndexError:%0A
+        if strict:%0A            return%0A
         lst, lst
@@ -1756,32 +1756,32 @@
 ept IndexError:%0A
+
             retu
@@ -1787,1941 +1787,4 @@
 urn%0A
-%0A%0Adef test_print(actual, expected):%0A    return 'PASS' if cmp(actual, expected)==0 else 'FAIL. %5Cn Expected: %7B%7D%5Cn Got:      %7B%7D'.format(expected, actual) %0A%0A%0Adef run_tests():%0A    from itertools import chain%0A    x = %5B1,2,3,4,5,6,7,8,9,0%5D%0A    y = %5B'a','b','c','d','e','f','g','h','i','j'%5D%0A    print 'compare to zip (flattened) :', test_print(list(ratio_merge(x,y)),list(chain(*zip(x,y))))%0A%0A    print '75:25 ratio (limited to 10):',  test_print(list(ratio_merge(x,y,0.75,10)), %5B1, 'a', 2, 3, 4, 'b', 5, 6, 7, 'c'%5D)%0A    print '25:75 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.25,10)), %5B1, 'a', 'b', 'c', 2, 'd', 'e', 'f', 3, 'g'%5D)%0A    print '70:30 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.7,10)), %5B1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7%5D)%0A    print '30:70 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.3,10)), %5B1, 'a', 'b', 'c', 2, 'd', 'e', 3, 'f', 'g'%5D)%0A    print '70:30 ratio (limited to 9):', test_print(list(ratio_merge(x,y,0.7,9)), %5B1, 'a', 2, 3, 'b', 4, 5, 'c', 6%5D)%0A    print '70:30 ratio (limited to 10):', test_print(list(ratio_merge(x,y,0.7,10)), %5B1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7%5D)%0A    print '70:30 ratio (limited to 11):', test_print(list(ratio_merge(x,y,0.7,11)), %5B1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7, 8%5D)%0A    print '70:30 ratio (unlimited):', test_print(list(ratio_merge(x,y,0.7)), %5B1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7, 8, 'd', 9, 0, 'e', 'f', 'g', 'h', 'i', 'j'%5D)%0A    print '70:30 ratio (unlimited, but only 3 elements in second list):', test_print(list(ratio_merge(x,y%5B:3%5D,0.7)), %5B1, 'a', 2, 3, 'b', 4, 5, 'c', 6, 7, 8, 9, 0%5D)%0A    print '70:30 ratio (unlimited, but only 3 elements in first list):', test_print(list(ratio_merge(x%5B:3%5D,y,0.7)), %5B1, 'a', 2, 3, 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'%5D)%0A    print '70:30 ratio (limited to 10, but only 3 elements in first list):', test_print(list(ratio_merge(x%5B:3%5D,y,0.7,10)), %5B1, 'a', 2, 3, 'b', 'c', 'd', 'e', 'f', 'g'%5D)%0A%0Arun_tests()%0A

add strict mode and seperate tests from implementation