def is_odd(n):return n % 2 == 1newlist = filter(is_odd, range(1,11))print(list(newlist))
举一反三
- def is_odd(n):return n%2 == 1lst1 = filter(is_odd,[1,2,3,4,5,6,7,8,9,10])list(lst1)值为?
- 下列函数能够求n的阶乘n!的是 A: f = lambda n: n! B: def f(n): s=1 for i in range(n): s = s * i return s C: def f(n): s=1 for i in range(n,0,-1): s = s * i return s D: def f(n): if n == 1: return 1 else: return f(n-1)*n
- 给一段代码defis_odd(n):returnn%2==0newlist=filter(is_odd,[1,2,3,4,5,6,7,8,9,10])foriteminnewlist:print(item)其输出结果是? A: [2,4,6,8,10] B: [1,3,5,7,10] C: [1,3,5,7,9] D: [1,3,5,6,9]
- 函数f打印出1,2,3的6个排列,空缺语句是 def f(n): for a in range(1,n): for b in range(1,n): for c in range(1,n): if ______________: print(a,b,c) _________
- 智慧职教: def f(n): if n==0: return 0 elif n==1: return 1 return f(n-1)+f(n-2) print(4) 结果是