※ 引述《freelancer (三十亿人的世界)》之铭言:
: level 0 :
: val = your_input
: total = 0
: for item in val:
: total += 1 / item
: level 1 :
: val = your_input
: total = 0
: val = [1 / item for item in val]
: total = sum(val)
: level 2 :
: val = your_input
: total = sum(map(lambda k : 1 / k, val))
level 3:
val = your_input
total = sum(1 / item for item in val)
Yes, this is faster than map(). :)