Ask Your Question

Revision history [back]

This function should do it:

def change_list(A):
    B = [] # new list
    n = 0 # integer to insert
    for i, pair in enumerate(A):
        B.append((pair[0] + (n,), pair[1]))
        # i counts the entries in A, so increment n every third time:
        # whenever i is congruent to 2 mod 3
        if i % 3 == 2:
            n += 1
    return B

This function should do it:just inserts 0 at the end of the 0th tuple in each pair:

def change_list(A):
    B = [] # new list
    for pair in enumerate(A):
        B.append((pair[0] + (0,), pair[1]))
    return B

So modify it to count the entries and increment every third time:

def change_list(A):
    B = [] # new list
    n = 0 # integer to insert
    for i, pair in enumerate(A):
        B.append((pair[0] + (n,), pair[1]))
        # i counts the entries in A, so increment n every third time:
        # whenever i is congruent to 2 mod 3
        if i % 3 == 2:
            n += 1
    return B

This function just inserts 0 at the end of the 0th tuple in each pair:

def change_list(A):
change_list_wrong(A):
    B = [] # new list
    for pair in enumerate(A):
        B.append((pair[0] + (0,), pair[1]))
    return B

So modify it to count the entries and increment every third time:

def change_list(A):
    B = [] # new list
    n = 0 # integer to insert
    for i, pair in enumerate(A):
        B.append((pair[0] + (n,), pair[1]))
        # i counts the entries in A, so increment n every third time:
        # whenever i is congruent to 2 mod 3
        if i % 3 == 2:
            n += 1
    return B

This function just inserts 0 at the end of the 0th tuple in each pair:

def change_list_wrong(A):
    B = [] # new list
    for pair in enumerate(A):
A:
        B.append((pair[0] + (0,), pair[1]))
    return B

So modify it to count the entries and increment every third time:

def change_list(A):
    B = [] # new list
    n = 0 # integer to insert
    for i, pair in enumerate(A):
        B.append((pair[0] + (n,), pair[1]))
        # i counts the entries in A, so increment n every third time:
        # whenever i is congruent to 2 mod 3
        if i % 3 == 2:
            n += 1
    return B