向元组中的所有值添加整数

Siw*_*wel 5 python tuples python-2.7

在如下所示的代码中编辑元组的推荐/最pythonic方式是什么?

tup_list = [(1, 2), (5, 0), (3, 3), (5, 4)]
max_tup = max(tup_list)
my_tup1 = (max_tup[0] + 1, max_tup[1] + 1)
my_tup2 = tuple(map(lambda x: x + 1, max_tup))
my_tup3 = max([(x+1, y+1) for (x, y) in tup_list])
Run Code Online (Sandbox Code Playgroud)

上述三种方法中哪一种更受欢迎,或者有更好的方法吗?(当然应该(6, 5)在这个例子中返回).

有一种诱惑可以做类似的事情

my_tup = max(tup_list)[:] + 1
Run Code Online (Sandbox Code Playgroud)

要么

my_tup = max(tup_list) + (1, 1)
Run Code Online (Sandbox Code Playgroud)

然而,这些都不明显.

che*_*ner 10

只需使用生成器表达式tuple:

my_tup = tuple(x+1 for x in max_tup)
# or my_tup = tuple(x+1 for x in max(tup_list))
Run Code Online (Sandbox Code Playgroud)