siple for in expression

Mark Wooding mdw at distorted.org.uk
Tue Mar 3 22:28:51 CET 2009


"Matko" <IvaStipancic at inet.hr> writes:

> Can someone help me to understand the following code:
>
> uv_face_mapping = [[0,0,0,0] for f in faces]

It constructs a fresh list, with the same number of elements as are in
the iterable object referred to by `faces', and where each element is a
distinct list of four zero-valued integer objects; it then makes
uv_face_mapping be a name for this list.

(This is therefore not the same as

        uv_face_mapping = [[0, 0, 0, 0]] * len(faces)

which constructs a list, each of whose elements is (well, refers to) the
/same/ list of four zero-valued integers.)

-- [mdw]



More information about the Python-list mailing list