Star * operator on left vs right side of an assignment statement

The difference between these two cases are explained when also taking into consideration the initial PEP for extended unpacking: PEP 3132 — Extended iterable unpacking. In the Abstract for that PEP we can see that: This PEP proposes a change to iterable unpacking syntax, allowing to specify a “catch-all” name which will be assigned a … Read more

How do I convert a tuple of tuples to a one-dimensional list using list comprehension? [duplicate]

it’s typically referred to as flattening a nested structure. >>> tupleOfTuples = ((1, 2), (3, 4), (5,)) >>> [element for tupl in tupleOfTuples for element in tupl] [1, 2, 3, 4, 5] Just to demonstrate efficiency: >>> import timeit >>> it = lambda: list(chain(*tupleOfTuples)) >>> timeit.timeit(it) 2.1475738355700913 >>> lc = lambda: [element for tupl in … Read more

asterisk in tuple, list and set definitions, double asterisk in dict definition

This is PEP-448: Additional Unpacking Generalizations, which is new in Python 3.5. The relevant change-log is in https://docs.python.org/3/whatsnew/3.5.html#pep-448-additional-unpacking-generalizations: PEP 448 extends the allowed uses of the * iterable unpacking operator and ** dictionary unpacking operator. It is now possible to use an arbitrary number of unpackings in function calls: >>> >>> print(*[1], *[2], 3, *[4, … Read more