【Kata Daily 191012】Find 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]

原文地址:https://www.cnblogs.com/bcaixl/p/11658775.html

时间: 2025-01-17 05:13:52

【Kata Daily 191012】Find numbers which are divisible by given number的相关文章

【Kata Daily 2】Calculating with Functions

原题: This time we want to write calculations using functions and get the results. Let's have a look at some examples: seven(times(five())) # must return 35 four(plus(nine())) # must return 13 eight(minus(three())) # must return 5 six(divided_by(two())

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

题目: Create a method that takes an array/list as an input, and outputs the index at which the sole odd number is located. This method should work with arrays with negative numbers. If there are no odd numbers in the array, then the method should outpu

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

题目: You are given an input string. For each symbol in the string if it's the first character occurence, replace it with a '1', else replace it with the amount of times you've already seen it... But will your code be performant enough? Examples: input

【Kata Daily 190924】Difference of Volumes of Cuboids(长方体的体积差)

题目: In this simple exercise, you will create a program that will take two lists of integers, a and b. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids a and b. You must find the difference of the cuboids'

【Kata Daily 191010】Grasshopper - Summation(加总)

题目: Summation Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. For example: summation(2) -> 3 1 + 2 summation(8) -> 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 解题方法: 很简单的题目: de

【USACO 2.2】Runaround Numbers

找出第一个大于n的数满足:每一位上的数都不同,且没有0,第一位开始每次前进当前这位上的数那么多位,超过总位数就回到开头继续往前进,最后能不能每个位都到过一次且回到第一位,$n<10^9$. 暴力,每次n++后模拟一边判断是否符合条件. /* TASK:runround LANG:C++ */ #include<cstdio> #include<cstring> using namespace std; int n; int get(int now,int step,int l

【Java并发.3】对象的共享

本章将介绍如何共享和发布对象,从而使他们能够安全地由多个线程同时访问.这两章合在一起就形成了构建线程安全类以及通过 java.util.concurrent 类库来构建开发并发应用程序的重要基础. 3.1 可见性 可见性是一种复杂的属性,因为可见性中的错误总是违背我们的直觉.为了确保多个线程之间对内存写入操作的可见性,必须使用同步机制. 在下面的清单中 NoVisibility 说明了当多个线程在没有同步的情况下共享数据出现的错误.主线程启动读线程,然后将 number 设为 42,并将 rea

poj 3252 Round Numbers 【推导&#183;排列组合】

以sample为例子 [2,12]区间的RoundNumbers(简称RN)个数:Rn[2,12]=Rn[0,12]-Rn[0,1] 即:Rn[start,finish]=Rn[0,finish]-Rn[0,start-1] 所以关键是给定一个X,求出Rn[0,X] 现在假设X=10100100  这个X的二进制总共是8位,任何一个小于8位的二进制都小于X 第一部分,求出长度为[0,7]区间内的二进制是RoundNumber的个数  对于一个长度为Len的二进制(最高位为1),如何求出他的Rou

hdoj 1492 The number of divisors(约数) about Humble Numbers 【数论】【质因子分解 求和】

定理:一个正整数 n 可以用素因子唯一表示为 p1^r1 * p2^r2 * ... pk^rk (其中 pi 为素数) , 那么这个数的因子的个数就是,(r1+1)*(r2+1)*...*(rk+1). 理解:为什么是加1之后再相乘,因为一个数的的因子数至少为1和他自身,但因为r1,r2..可以为0,所以因子的个数为(r1+1)... 拓展一下: 定理1: 一个正整数 n 可以用素因子唯一表示为 p1^r1 * p2^r2 * ... pk^rk (其中 pi 为素数) , 那么这个数的因子的