我正在为初学者开设 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!"
由于感叹号,它只会说文本包含不允许的字符。
如果文本中每个单词中的每个字母都与字符匹配,我将如何进行比较?
感谢您的帮助,非常感谢。