Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # balanced_columns_demo.py
- text_height = 18
- button_height = 32
- additional_ypadding = 12
- data = [
- ("Galleries", 5),
- ("Cultural Centres", 5),
- ("Performances", 4),
- ("Workshops", 4),
- ("Heritage Sites", 3),
- ("Public Art", 3),
- ("Lectures", 2),
- ("Film Screenings", 2),
- ("Pubs", 4),
- ("Lounges", 3),
- ("Patios", 4),
- ("Billiards", 3),
- ("Coffeehouses", 3),
- ("Wine Bars", 2),
- ("Live Music", 3),
- ("Trivia Nights", 2),
- ("Walking Trails", 5),
- ("Golf", 3),
- ]
- blocks = []
- for name, rows in data:
- px_height = rows * text_height + button_height + additional_ypadding
- blocks.append((name, px_height))
- column_count = 3 # or 4 or 5
- columns = [[] for _ in range(column_count)]
- heights = [0] * column_count
- blocks_sorted = sorted(blocks, key=lambda x: x[1], reverse=True)
- for name, h in blocks_sorted:
- idx = heights.index(min(heights))
- columns[idx].append((name, h))
- heights[idx] += h
- print("Column heights:", heights)
- print("Imbalance:", max(heights) - min(heights))
- print()
- for i, col in enumerate(columns):
- print(f"Column {i+1}:")
- for name, h in col:
- print(f" {name} ({h}px)")
- print()
Advertisement
Add Comment
Please, Sign In to add comment