collection data types using list comprehension in this case reduced the code from four lines to two-- small savingsbut one that can add up quite lot in large projects since list comprehensions produce liststhat isiterablesand since the syntax for list comprehensions requires an iterableit is possible to nest list comprehensions this is the equivalent of having nested for in loops for exampleif we wanted to generate all the possible clothing label codes for given sets of sexessizesand colorsbut excluding labels for the full-figured females whom the fashion industry routinely ignoreswe could do so using nested for in loopscodes [for sex in "mf"malefemale for size in "smlx"smallmediumlargeextra large if sex ="fand size =" "continue for color in "bgw"blackgraywhite codes append(sex size colorthis produces the item list['msb''msg''flw'the same thing can be achieved in just couple of lines using list comprehensioncodes [ for in "mffor in "smlxfor in "bgwif not ( ="fand =" ")hereeach item in the list is produced by the expression alsowe have used subtly different logic for the list comprehension where we skip invalid sex/size combinations in the innermost loopwhereas the nested for in loops version skips invalid combinations in its middle loop any list comprehension can be rewritten using one or more for in loops if the generated list is very largeit may be more efficient to generate each item as it is needed rather than produce the whole list at once this can be achieved by using generator rather than list comprehension we discuss this laterin set types || set type is collection data type that supports the membership operator (in)the size function (len())and is iterable in additionset types at least provide set isdisjoint(methodand support for comparisonsas well as support for the bitwise operators (which in the context of sets are used for unionintersectionetc python provides two built-in set typesthe mutable set type and the immutable frozenset when iteratedset types provide their items in an arbitrary order generators