我喜欢 Python 的 sum 函数:
I like the Python sum function :
>>> z = [1] * 11
>>> zsum = sum(z)
>>> zsum == 11
True
我想要使用 xor (^) 而不是添加 (+) 的相同功能.我想使用地图.但我无法弄清楚如何做到这一点.有什么提示吗?
I want the same functionality with using xor (^) not add (+). I want to use map. But I can not work out how to do this. Any hints?
我对此不满意:
def xor(l):
r = 0
for v in l: r ^= v
return v
我想要一个使用地图的 1 班轮.提示?
I want a 1 liner using map. Hints?
zxor = reduce(lambda a, b: a ^ b, z, 0)
import operator
zxor = reduce(operator.xor, z, 0)
这篇关于Python 等价于 sum() 使用 xor()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
列表字典中的总和值Sum values in a dict of lists(列表字典中的总和值)
如何在 Python 中对文本文件中的数字求和How to sum numbers from a text file in Python(如何在 Python 中对文本文件中的数字求和)
什么是类似于 sum() 的减法函数,用于减去列表中What is a subtraction function that is similar to sum() for subtracting items in list?(什么是类似于 sum() 的减法函数,用于减去列表中的
python中的求和矩阵列sum matrix columns in python(python中的求和矩阵列)
N个列表元素的总和pythonsum of N lists element-wise python(N个列表元素的总和python)
带有列表参数的 Python sum() 函数Python sum() function with list parameter(带有列表参数的 Python sum() 函数)