一个简单的计数代码,我不明白它是如何工作的
A simple counting code which i dont understand how it work
words = "Fine and Cloudy"
vowels = 'aeiouAEIOU'
my_words = [words.index(c) for c in words if c not in vowels and words.count(c) == 1]
print(my_words)
我只是不明白为什么输出是 [0, 9, 10, 14]
以及这个简单的代码是如何工作的?
有人可以详细解释吗?请!
提前致谢。
它打印字符串 "Fine and Cloudy" 中那些非元音字母且恰好出现一次的字母的位置。这些是 "F"(位置 0)、"C"(位置 9)、"l"(位置 10)和 "y"(位置 14)。
words = "Fine and Cloudy"
vowels = 'aeiouAEIOU'
my_words = [words.index(c) for c in words if c not in vowels and words.count(c) == 1]
print(my_words)
我只是不明白为什么输出是 [0, 9, 10, 14]
以及这个简单的代码是如何工作的?
有人可以详细解释吗?请!
提前致谢。
它打印字符串 "Fine and Cloudy" 中那些非元音字母且恰好出现一次的字母的位置。这些是 "F"(位置 0)、"C"(位置 9)、"l"(位置 10)和 "y"(位置 14)。