Kata Daily 191012Find numbers which are divisible by given number

Posted bcaixl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kata Daily 191012Find numbers which are divisible by given number相关的知识,希望对你有一定的参考价值。

题目:

Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array of numbers and the second is the divisor.

Example

divisible_by([1, 2, 3, 4, 5, 6], 2) == [2, 4, 6]

 

解题方法:

def divisible_by(numbers, divisor):
    return [x for x in numbers if x%divisor == 0]

 

以上是关于Kata Daily 191012Find numbers which are divisible by given number的主要内容,如果未能解决你的问题,请参考以下文章

Kata Daily 190923Odder Than the Rest(找出奇数)

Kata Daily 190917Numericals of a String(字符出现的次数)

[Daily Coding Problem] Find the total number of solutions of a linear equation of n variables

[Daily Coding Problem] 1 (LeetCode 1). Find if two numbers in an array add up to k

CTF-reverse-daily-wow

Daily LeetCode ---- 数组