【问题标题】:write a function of evenNumOfOdds (L) that takes in a list of positive integers L and returns True if there are an even number of odd integers in L编写一个 evenNumOfOdds (L) 函数,它接受正整数 L 的列表,如果 L 中有偶数个奇数则返回 True
【发布时间】:2020-05-19 13:04:04
【问题描述】:
                                  Test Cases: 

测试用例参数(L)返回值 1 [1,2,3,6,10] 真 2 [1,3,5,7,9,10] 错误 3 [10,30,50,70,120] 真(0 为偶数) 4 [7,1,17,15,13,​​5,2,1,27,15,14,4] 假 5 [1,2,3,4,5,6,7,8,9,10,11,12] 真

【问题讨论】:

  • 您好,欢迎来到 stackoverflow,请参考 How do I ask a good questionHelp Center 获取有关如何提出好问题的指导。请在您的问题中包含您迄今为止尝试过的内容。 SO 不是编写代码的“代码工厂”。

标签: python spyder


【解决方案1】:
def evenNumOfOdds(list_):
return len([i for i in list_ if i%2 == 1])%2 == 0

【讨论】:

    猜你喜欢
    • 2016-08-22
    • 2020-07-24
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 2014-02-16
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多