generated at
マンダラート生成コード
マンダラート生成コード
書き初め2024nishio
python
base = [ ["1", "2", "3"], ["4", "", "5"], ["6", "7", "8"], ] def f(x): def concat(b): if not x: return b if not b: return f"[[{x}]]" return f"{x}-{b}" if x else b return apply_tree(base, concat) def apply_tree(tree, func): result = [] for e in tree: if isinstance(e, str): result.append(func(e)) else: result.append(apply_tree(e, func)) return result def print_tree_matrix(tree): for layer in tree: for row in zip(*layer): print("\t".join(sum(row, []))) print_tree_matrix(apply_tree(base, f))

出力
output
1-11-21-32-12-22-33-13-23-3
1-4[[1]]1-52-4[[2]]2-53-4[[3]]3-5
1-61-71-82-62-72-83-63-73-8
4-14-24-31235-15-25-3
4-4[[4]]4-5455-4[[5]]5-5
4-64-74-86785-65-75-8
6-16-26-37-17-27-38-18-28-3
6-4[[6]]6-57-4[[7]]7-58-4[[8]]8-5
6-66-76-87-67-77-88-68-78-8