I want to be able to take a sequence like:
my_sequence = ['foo', 'bar', 'baz', 'spam', 'eggs', 'cheese', 'yogurt']
Use a function like:
my_paginated_sequence = get_rows(my_sequence, 3)
To get:
[['foo', 'bar', 'baz'], ['spam', 'eggs', 'cheese'], ['yogurt']]
This is what I came up with by just thinking through it:
def get_rows(sequence, num):
count = 1
rows = list()
cols = list()
for item in sequence:
if count == num:
cols.append(item)
rows.append(cols)
cols = list()
count = 1
else:
cols.append(item)
count += 1
if count > 0:
rows.append(cols)
return rows
I ask questions like this because I always feel like there is some Jedi way of doing things that I just don't know about since I work by myself and never went to school, like:
x = LNode(format="paginator").initialize(3)
or something, you know what I mean?