def test_distribute_with_extra():
        food = ["apple", "banana", "carrot", "daikon", "egg", "fish",
                "gelato", "honey", "EXTRA"]
        eq_(distribute(food, 3, "H", ""), [['apple', 'banana', 'carrot'],
            ['daikon', 'egg', 'fish'], ['gelato', 'honey', 'EXTRA']])
        eq_(distribute(food, 3, "V", ""), [['apple', 'daikon', 'gelato'],
            ['banana', 'egg', 'honey'], ['carrot', 'fish', 'EXTRA']])
        eq_(distribute(food, 2, "H", ""), [['apple', 'banana'], ['carrot',
            'daikon'], ['egg', 'fish'], ['gelato', 'honey'], ['EXTRA', '']])
        eq_(distribute(food, 2, "V", ""), [['apple', 'fish'], ['banana',
            'gelato'], ['carrot', 'honey'], ['daikon', 'EXTRA'], ['egg', '']])
Beispiel #2
0
def test_distribute():
    food = [
        "apple", "banana", "carrot", "daikon", "egg", "fish", "gelato", "honey"
    ]
    eq_(distribute(food, 3, "H", ""),
        [['apple', 'banana', 'carrot'], ['daikon', 'egg', 'fish'],
         ['gelato', 'honey', '']])
    eq_(distribute(food, 3, "V", ""),
        [['apple', 'daikon', 'gelato'], ['banana', 'egg', 'honey'],
         ['carrot', 'fish', '']])
    eq_(distribute(food, 2, "H", ""),
        [['apple', 'banana'], ['carrot', 'daikon'], ['egg', 'fish'],
         ['gelato', 'honey']])
    eq_(distribute(food, 2, "V", ""),
        [['apple', 'egg'], ['banana', 'fish'], ['carrot', 'gelato'],
         ['daikon', 'honey']])
Beispiel #3
0
def columnize_as_rows(lis, columns, horizontal=False, fill=None):
    """Like 'zip' but fill any missing elements."""
    data = distribute(lis, columns, horizontal, fill)
    rowcount = len(data)
    length = max(len(x) for x in data)
    for c, lis in enumerate(data):
        n = length - len(lis)
        if n > 0:
            extension = [fill] * n
            lis.extend(extension)
    return list(zip(*data))
Beispiel #4
0
def columnize_as_rows(lis, columns, horizontal=False, fill=None):
    """Like 'zip' but fill any missing elements."""
    data = distribute(lis, columns, horizontal, fill)
    rowcount = len(data)
    length = max(len(x) for x in data)
    for c, lis in enumerate(data):
        n = length - len(lis)
        if n > 0:
            extension = [fill] * n
            lis.extend(extension)
    return zip(*data)