20 lines
627 B
Python
20 lines
627 B
Python
"""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
|