是否有任何允许Python 3中的元组进行元素操作的内置函数?如果没有,那么执行这些操作的“pythonic”方法是什么?Python中的元组的元素操作
示例:我想获取a
和b
之间的百分比差异,并将它们与某个阈值th
进行比较。
>>> a = (1, 2, 4)
>>> b = (1.1, 2.1, 4.1)
>>> # compute pd = 100*abs(a-b)/a = (10.0, 5.0, 2.5)
>>> th = 3
>>> # test threshold: pd < th => (False, False, True)
我们在谈论地图功能吗? http://docs.python.org/release/3.1.5/library/functions.html#map – bpgergo
结合zip? http://docs.python.org/release/3.1.5/library/functions.html#zip – bpgergo