类型别名TypeAlias

from collections.abc import Iterable
from typing import TypeAlias

FromTo = tuple[str, str]  # 3.10之前
FromTo: TypeAlias = tuple[str, str] # 3.10之后推荐使用TypeAlias


def zip_replace(text: str, changes: Iterable[FromTo]) -> str:
    for from_, to in changes:
        text = text.replace(from_, to)
    return text

posted @ 2023-08-28 08:44  我在路上回头看  阅读(14)  评论(0编辑  收藏  举报