map,reduce,filter基礎實現

2022-06-19 11:27:10 字數 1173 閱讀 2531

#

coding=gbk

from operator import

add#

匯入加法

#map 函式名 , 序列物件

print(list(map(str,range(5))))

print(list(map(len,['

abc','

1234

'])))

#[3, 4]

for num in map(add,range(3),range(1,4)):

#對 0+1 , 1+2 , 2+3

print

(num)

from functools import

reduce

from operator import

add,mul,or_

seq = range(1,10)

#1~9 的所有元素

print

(reduce(add,seq))

#連加,seq 中的每乙個元素

print

(reduce(mul,seq))

#連乘,seq 中的每乙個元素

seq = [,,,,]

print

(reduce(or_,seq))

#將 seq 中的元素並集在一起,or_

seq = ['

abcd

','1234

',',.?!

',''

]print

(list(filter(str.isdigit,seq)))

#只保留元素全是數字的

print

(list(filter(str.isalpha,seq)))

#只保留元素全是字母的

print

(list(filter(none,seq)))

#保留等價於 true 的元素

gen = (2 ** i for i in range(5))

for i in

gen:

print(i,end = '')

print

()x,y,z = map(int,'

123'

)print(x,y,z)

2020-06-21

C STL基礎實操

include include using namespace std intmain include include using namespace std intmain include include using namespace std intmain include include in...

python基礎實訓 python基礎實踐(四)

coding utf 8 author sweeping monk why 為什麼要組織列表?print why chicken soup t因為你無法控制使用者提供資料的順序。permanent ordering.sort 永久性修改列表元素的排列順序。前提是所有元素值第一位都是小寫 或者全是大寫...

C語言基礎實列

1.求1000以內素數 素數 除1和它本身以外不能被任何數整除 iniclude stdio.h int fun int m 若標誌變數h為零,則不是素數,終止迴圈 return h int main 2.1000以內完數 完數 除自身以外的約數之和等於它本身 include stdio.h int...