>>> transposed =[] >>>for i in range(4): ... transposed.append([row[i] for row in matrix]) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] 

which, in turn, is the same as: 

>>> transposed =[] >>>for i in range(4): ... # the following 3 lines implement the nested listcomp ... transposed_row=[] ... for row in matrix: ... transposed_row.append(row[i]) ... transposed.append(transposed_row) ... >>> transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] 

In the real world, you should prefer built-in functions to complex flow statements. The$_{zip()}$function would do a great job for this use case: 

>>> list(zip (*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] 

See Unpacking Argument Lists for details on the asterisk in this line. 

## 5.2 The del statement 

There is a way to remove an item from a list given its index instead of its value: the$_{del}$statement. This differs from the$_{pop()}$ method which returns a value. The$_{del}$statement can also be used to remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice). For example: 

>>> a =[-1,1,66.25 ,333 ,1234.5 ] >>>del a[0] >>> a [1, 66.25, 333, 333, 1234.5] >>>del a[2:4] >>> a [1, 66.25, 1234.5] >>>del a[:] >>> a [] 

$_{del}$can also be used to delete entire variables: 

>>>del a 

Referencing the name$_{a}$ hereafter is an error (at least until another value is assigned to it). We’ll find other uses for $_{del}$later. 

