Doctest字母提取
提取文本字符串中存在的所有唯一字母。 :param text: 字符串数据 :return: 字符串中所有唯一字母的小写元组
def extract_letters(text):
"""
Extract all the unique letters present in the text string.
:param text: string data
:return: a tuple of all the unique letters of the string in lowercase
>>> extract_letters("Python 123 is C00!_")
('p', 'y', 't', 'h', 'o', 'n', 'i', 's', 'c')
>>> extract_letters("Numbers Are Overrated!")
('n', 'u', 'm', 'b', 'e', 'r', 's', 'a', 'o', 'v', 't', 'd')
"""
letters = []
users = []
for i in range(len(text)):
if (text[i]).isalpha():
letters.append(text[i].lower())
for i in range(len(letters)):
if letters[i] not in users:
users.append(letters[i])
return (users)
想知道是否有一种方法可以使输出用尖括号代替方括号,以便匹配并完成文档测试?
Extract all the unique letters present in the text string.
:param text: string data
:return: a tuple of all the unique letters of the string in lowercase
def extract_letters(text):
"""
Extract all the unique letters present in the text string.
:param text: string data
:return: a tuple of all the unique letters of the string in lowercase
>>> extract_letters("Python 123 is C00!_")
('p', 'y', 't', 'h', 'o', 'n', 'i', 's', 'c')
>>> extract_letters("Numbers Are Overrated!")
('n', 'u', 'm', 'b', 'e', 'r', 's', 'a', 'o', 'v', 't', 'd')
"""
letters = []
users = []
for i in range(len(text)):
if (text[i]).isalpha():
letters.append(text[i].lower())
for i in range(len(letters)):
if letters[i] not in users:
users.append(letters[i])
return (users)
Was wondering if there was a way to make the output curved brackets instead of square brackets so it matches and the doctest completes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: