def partition(iterable, cols=4): if not iterable: return () try: cols = int(cols) except (ValueError, TypeError): return None the_tuple = tuple(iterable) maxrows = int(ceil(len(the_tuple)/float(cols))) columns = grouper(maxrows, the_tuple) return zip(*tuple(columns))
def partition(iterable, cols=4): "Split an iterable into columns" if not iterable: return () try: cols = int(cols) except (ValueError, TypeError): return None the_tuple = tuple(iterable) maxrows = int(ceil(len(the_tuple) / float(cols))) columns = grouper(maxrows, the_tuple) return zip(*tuple(columns))
def show_badges_as_table(user, cols=4): outer_template = '<table>{}</table>' cell = '<td>{}</td>' row = '<tr>{}</tr>\n' single_col = '<tr><td>{}</td></tr>\n' badge_list = get_badges_for_user(user) if cols == 1: return [format_html(single_col, badge) for badge in badge_list] elif cols > 1: piecesize = int(ceil(len(badge_list) / float(cols))) badge_lists = grouper(piecesize, badge_list) outer = [] go_over = list(range(cols)) for p in range(piecesize): inner = [] for i in go_over: inner.append(format_html(cell, badge_list[i][p])) outer.append(format_html(row, ''.join(inner))) return format_html(outer_template, ''.join(outer))
def show_badges_as_table(user, cols=4): outer_template = u'<table>%s</table>' cell = u'<td>%s</td>' row = u'<tr>%s</tr>\n' single_col = u'<tr><td>%s</td></tr>\n' badge_list = get_badges_for_user(user) if cols == 1: return [single_col % badge for badge in badge_list] elif cols > 1: piecesize = int(ceil(len(badge_list) / float(cols))) badge_lists = grouper(piecesize, badge_list) outer = [] go_over = list(range(cols)) for p in range(piecesize): inner = [] for i in go_over: inner.append(cell % badge_list[i][p]) outer.append(row % u''.join(inner)) return outer_template % u''.join(outer)