Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7532229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:23:25+00:00 2026-05-30T05:23:25+00:00

I saw some code yesterday in this question that I had not seen before,

  • 0

I saw some code yesterday in this question that I had not seen before, this line in particular:

for xyz[num] in possible[num]:
    ...

So as this loop runs, the elements from possible[num] are assigned to the list xyz at position num. I was really confused by this so I did some tests, and here is some equivalent code that is a little more explicit:

for value in possible[num]:
    xyz[num] = value
    ...

I definitely intend to always use this second format because I find the first more confusing than it is worth, but I was curious… so:

Is there any good reason to use this “feature”, and if not, why is it allowed?

Here are a couple of stupid use cases I came up with (stupid because there are much better ways to do the same thing), the first is for rotating the letters of the alphabet by 13 positions, and the second is for creating a dictionary that maps characters from rot13 to the character 13 positions away.

>>> import string
>>> rot13 = [None]*26
>>> for i, rot13[i%26] in enumerate(string.ascii_lowercase, 13): pass
...
>>> ''.join(rot13)
'nopqrstuvwxyzabcdefghijklm'

>>> rot13_dict = {}
>>> for k, rot13_dict[k] in zip(rot13, string.ascii_lowercase): pass
...
>>> print json.dumps(rot13_dict, sort_keys=True)
{"a": "n", "b": "o", "c": "p", "d": "q", "e": "r", "f": "s", "g": "t", "h": "u", "i": "v", "j": "w", "k": "x", "l": "y", "m": "z", "n": "a", "o": "b", "p": "c", "q": "d", "r": "e", "s": "f", "t": "g", "u": "h", "v": "i", "w": "j", "x": "k", "y": "l", "z": "m"}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:23:27+00:00Added an answer on May 30, 2026 at 5:23 am

    The reason this is allowed is simplicity. The list of “loop variables” has the same grammar as any other assignment target. As an example, tuple unpacking is allowed in assignments, so it is allowed in for loops as well, and this is certainly quite useful. Defining a separate syntax for the assignement of loop variables would seem artificial to me — the semantics of regular assignment and loop variable assignments are the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently saw some code that reminded me to ask this question. Lately, I've
I saw some old code that had: <input type=submit name=submit onsubmit=somefunction(this) /> I was
I saw some code written by another developer that looks something like this: var
I saw some code on the apple website that goes like this id <NSFetchedResultsSectionInfo>
Ok, I was scanning through some code yesterday and I saw this, Code: public
I saw some code that had the controls in a flex box set to
I saw some code on an unrelated question but it got me curious as
I saw some code like this: try { db.store(mydata); } finally { db.cleanup(); }
const static int foo = 42; I saw this in some code here on
I recently saw some code from a college teacher where he had something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.