Add sage code
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
"""Utilities for converting integer colorings to named colors."""
|
||||
from typing import Any
|
||||
|
||||
COLORS = ['blue', 'red', 'green', 'yellow', 'purple']
|
||||
|
||||
def convert_coloring(
|
||||
coloring: dict[Any, int],
|
||||
vertices: list[Any] | None = None
|
||||
) -> dict[str, list[Any]]:
|
||||
"""Convert an integer coloring dict to a dict mapping color names to vertex lists."""
|
||||
colors: dict[str, list[Any]] = {}
|
||||
for k, v in coloring.items():
|
||||
if vertices and k not in vertices:
|
||||
continue
|
||||
color = COLORS[v]
|
||||
if color not in colors:
|
||||
colors[color] = []
|
||||
colors[color].append(k)
|
||||
return colors
|
||||
Reference in New Issue
Block a user