Q7

More written answers!

A

How are generators and lists similar? How are they different?


B

Let's say I'm inside a for loop, iterating through a large generator object (e.g. range). I come across a sequence of values I want to skip, moving several iterations ahead, but for whatever reason I don't know about continue. I decide to simply increment my loop variable by 5 inside the loop body after checking if it meets a certain condition. Will this work? Why or why not?


C

If I want to check if two lists contain identical elements irrespective of ordering, how could I do that?


D

I have four lists, each with N elements. I want to loop through them all simultaneously, so I zip() them together. How many elements will now be in my zip() generator?


E

I have a matrix, and to iterate through it I use nested for loops. In doing so, I check the value at each matrix element, looking for a specific match. If the match is found, I execute a break statement:

matrix = [ ... ]
for i in range(len(matrix)):
    for j in range(len(matrix[i])):
        if matrix[i][j] == some_value:
            break

What happens?