from pypinyin import pinyin, Style


def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False


# 带声调的(默认)
def yinjie(word):
    pinyin_list = []
    # heteronym=True开启多音字
    for old_pinyin_list in pinyin(word, heteronym=True, style=Style.TONE2):
        for old_pinyin in old_pinyin_list:
            s = ''
            num = ''
            for j in old_pinyin:
                if is_number(j):
                    num = j
                else:
                    s += j
            s += num
            pinyin_list.append(s)
    return pinyin_list

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2022-01-27
  • 2022-12-23
  • 2021-06-18
  • 2022-01-21
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案