【发布时间】:2016-10-08 17:02:47
【问题描述】:
我正在为初学者开设 Python 课程。 我们必须创建一个代码,将最多 6 个单词的输入转换为首字母缩写词。
在创建首字母缩写词之前,它必须检查单词是否只包含给定集合中的字符,但我不能只检查它是否在字母表中,因为我们使用的是具有特殊字符(õ、ä、ö)的本地字母表, ü)。
def main():
nr_of_words_limit = 6
chars = "abcdefghijklmnopqrstuvwõäöüxyz"
def not_allowed_characters_check(text, chars):
"""This checks if all words in text only include characters from chars"""
def acronym(text, chars, nr_of_words_limit):
"""Creates acronym after checking for not allowed characters"""
所以,在这种情况下:
text = "Hello World!"
由于感叹号,它只会说文本包含不允许的字符。
如果文本中每个单词中的每个字母都匹配字符,我将如何比较呢?
感谢您的帮助,非常感谢。
【问题讨论】: