You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normally in a for loop, you just do for <variable_name> in iterable:, but you can also do use anything that is a valid assignment target (An "lvalue" in C). Like for f()(g)[t].x in seq: is perfectly valid syntax.
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
Where exprlist is the assignment target. This means that the equivalent of {exprlist} = {next_value} is executed for each item in the iterable.
Normally, this is a single variable. For example, with for i in iterator:, the equivalent of i = next(iterator) is executed before every time the block after for is.
d['n'] = value sets the 'n' key to the given value, so the 'n' key is assigned to a value in the range each time, and printed.
The function uses enumerate() to generate a new value for i each time (A counter going up). It then sets the (just assigned) i key of the dictionary. For example, in the first example, unrolling the loop looks like:
Hey @MitalAshok Thanks for this cool suggestion. I've added your example in 753d0b6 . For brevity of the overall contents of the collection, I had to skip some of the content.
If you think it's missing something, or something is incorrect, feel free to reopen the issue.
Cheers!
Normally in a for loop, you just do
for <variable_name> in iterable:
, but you can also do use anything that is a valid assignment target (An "lvalue" in C). Likefor f()(g)[t].x in seq:
is perfectly valid syntax.Here is a draft:
For what?
Output:
Output:
💡 Explanation:
A
for
statement is defined in the Python grammar as:Where
exprlist
is the assignment target. This means that the equivalent of{exprlist} = {next_value}
is executed for each item in the iterable.Normally, this is a single variable. For example, with
for i in iterator:
, the equivalent ofi = next(iterator)
is executed before every time the block afterfor
is.d['n'] = value
sets the'n'
key to the given value, so the'n'
key is assigned to a value in the range each time, and printed.The function uses
enumerate()
to generate a new value fori
each time (A counter going up). It then sets the (just assigned)i
key of the dictionary. For example, in the first example, unrolling the loop looks like:The text was updated successfully, but these errors were encountered: