How to add with tuples
I have pseudo-code like this: if( b < a) return (1,0)+foo(a-b,b) I want to write it in python. But can python add tuples? What is the best way to code something like that? Do you want to do element-wise addition, or to append the tuples? By default python does (1,2)+(3,4) = (1,2,3,4) You could define your own as: def myadd(x,y): z = [] for i in range(len(x)): z.append(x[i]+y[i]) return tuple(z) Also, as @delnan's comment makes it clear, this is better written as def myadd(xs,ys): return tuple(x + y for x, y in izip(xs, ys)) or even more functionally: myadd = lambda xs,ys: tuple(x + y for x, y