Adding Values From Tuples of Same Length

后端 未结 6 993
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 05:07

In a graphical program I\'m writing using pygame I use a tuple representing a coordinate like this: (50, 50).

Sometimes, I call a function which returns another tupl

6条回答
  •  臣服心动
    2020-12-06 05:25

    List comprehension is probably more readable, but here's another way:

    >>> a = (1,2)
    >>> b = (3,4)
    >>> tuple(map(sum,zip(a,b)))
    (4,6)
    

提交回复
热议问题