% len_attr = len(attributes) switch = len_attr / 2 if not switch * 2 == len_attr: switch = switch + 1 counter = 1 lc1 = [] lc2 = [] for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']): if counter <= switch: lc1.append(a) else: lc2.append(a) counter = counter + 1 %> <%def name="form_col(l)"> % for a in l: <% attr = attributes[a] %>