What does this code below?


#1

Hi,

Can anyone here tell me what does zero in the code below? (In my return statement)

DISTRICTS=92
parties=['Tea Party', 'Coffee Party', 'Milk Party','House Party', 'Beach Party']
def initElection(parties):
    return [[0 for i in range(len(parties)) for j in range(DISTRICTS)]]

#2

lets do a regular for loop which adds to a list:

example = []
for i in range(25):
    example.append(0)

this would be the same as:

example = [0 for i in range(25)]

i on purpose used zero in both cases, so the 0 is what you are append to list (see the similarity between the two programs)


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.