从整数中减去元组

时间:2014-08-30 03:27:57

标签: python int tuples subtraction

for r in races:
    print r
    print 'Par ',r.par()
    print 'Quarter pars ', r.quarterpars()
    print ''

返回:

Par  75,

Quarter pars  Route (50, 57, 73, 86),

我需要从par:

中减去四分之一的句子
(75 - 50, 75 - 57, 75 - 73, 75 - 86),

= (25, 18, 2, -11),

Par是int,四分之一是tuple

2 个答案:

答案 0 :(得分:1)

In [82]: quarterPars = (50, 57, 73, 86)

In [83]: par = 75

In [84]: tuple(par-q for q in quarterPars)
Out[84]: (25, 18, 2, -11)

答案 1 :(得分:0)

>>> qp=(50, 57, 73, 86)
>>> p=75
>>> tuple(map(lambda e: p-e, qp))
(25, 18, 2, -11)