类型别名TypeAlias

纽二

关注

阅读 43

2023-10-23

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

-------------------------------------------

个性签名:代码过万,键盘敲烂!!!

精彩评论(0)

0 0 举报