⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 piglatin.py

📁 Dive into Python 中文版
💻 PY
字号:
"""Convert text to Pig LatinThis program is part of "Dive Into Python", a free Python book forexperienced programmers.  Visit http://diveintopython.org/ for thelatest version."""__author__ = "Mark Pilgrim (mark@diveintopython.org)"__version__ = "$Revision: 1.2 $"__date__ = "$Date: 2004/05/05 21:57:19 $"__copyright__ = "Copyright (c) 2002 Mark Pilgrim"__license__ = "Python"import redef _wordToPigLatin(match):    word = match.group()    consonants = match.group(1)    restOfWord = match.group(2)    # put consonants after rest of word, and add "ay"    result = "%s%say" % (restOfWord, consonants)    # if word was all uppercase, make result uppercase    if word == word.upper():        result = result.upper()    # if word was capitalized, make result capitalized    elif word == word.capitalize():        result = result.capitalize()    return resultdef pigLatin(source):    pattern = re.compile(r'\b([bcdfghjklmnpqrstvwxyz]*)(\w+)\b', re.IGNORECASE)    return pattern.sub(_wordToPigLatin, source)    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -