MIQIWEI 发表于 2020-5-2 10:47:49

有关list的问题!谢谢大佬们!

在 print(get_o_words_count(['OUT','water','is','for','No']))怎么来得出包含“o”或者“O”的word有几个呢? 是用什么方法呢

wp231957 发表于 2020-5-2 10:51:12

把那个自定义函数填补全也

永恒的蓝色梦想 发表于 2020-5-2 10:52:23

前面加上这么一句get_o_words_count=lambda l:sum(('o' in i or 'O' in i) for i in l)

MIQIWEI 发表于 2020-5-2 11:37:49

永恒的蓝色梦想 发表于 2020-5-2 10:52
前面加上这么一句

嗯嗯 谢谢 这道题是定义一个函数 get_o_count(word_list)   which is passed a list of strings as a parameter.
The function returns the count of all the words in the parameter list which contain the letter 'o' or 'O'.
但是我的代码写出来总是为0的 我不知道什么原因

永恒的蓝色梦想 发表于 2020-5-2 11:54:08

MIQIWEI 发表于 2020-5-2 11:37
嗯嗯 谢谢 这道题是定义一个函数 get_o_count(word_list)   which is passed a list of strings as a p ...

发代码
页: [1]
查看完整版本: 有关list的问题!谢谢大佬们!