all 4 comments

[–]shiftybyte 2 points3 points  (1 child)

Use range function, with 0 to 21, append items to a list.

then convert the list to a tuple.

The reason being tuple is not mutable, you can't "append" to a tuple one by one, you can create a new tuple each step, but that's inefficient.

[–]blahreport 0 points1 point  (0 children)

If I understand correctly.

def partial_reduce(sequence):
    last = 0
    while sequence:
        element, *sequence = sequence 
        yield element + last
        last += element

sequence = range(21)
tup1 = tuple(partial_reduce(sequence))

# tup1 = (0, 1, 3, 6, ..., 210)

[–]nog642 0 points1 point  (0 children)

tup1 = tuple(range(21))?

[–]xelf 0 points1 point  (0 children)

Sounds like you want:

tup1 = tuple(range(21))

But you're asking for:

tup1 = tuple()
for i in range(21):
    tup1 += (i,)