-6

I wrote a question on how I can turn items from a Python list into variables (Variables for unknown amount of list items in Python) (now deleted).

It said my question was a duplicate, but when I checked the duplicate, the question was about a Python program skimming over some parts of a list. How can I change the question so it can get reopened?

1
  • 8
    I agree that the Q&A used to close this does not appear to be a true duplicate, and would guess that there are better duplicate Q&A's that could/should have been used, but having said that, the question itself looks to be a possible XY Problem where you ask how to solve a specific code problem when the best solution is to use a completely different approach. Better that you tell us the overall problem that you're trying to solve by this rather than how you're currently trying to solve it. The reference is more important than any variable "name". Aug 20 at 22:12

2 Answers 2

12

"Dynamically create variables for elements of the list" is a very common problem people invent when their start learning to code. Indeed your question should be closed as duplicate as that type of questions asked for many languages in all sorts of variants, including Python - How can I create new variables in a loop, with the names and values coming from a list?.

It is possible that the person who closed the question just mispasted the duplicate - it is very easy to fix, as any gold-badge holder can edit the list to replace with the correct one*. We don't reopen questions that were closed for less-than-exact reason (also Python may be special tag for that).

If you actually think your question is unique - indeed it is somewhat easy to resolve it that way too: edit the question to clarify how the existing questions on the topic of creating variables at run time in Python did not help (i.e., clarify why the dictionary approach from the one I linked above did not work) and ideally explain what your actual goal is along with an explanation how you plan to use dynamically-created variables to do so (which is especially suspicious as I'm pretty sure you can't "to print the variable names" in Python either).


* Shortly after this answer juanpa.arrivillaga who originally closed the question commented: "I copied the wrong link, duplicate target updated" confirming that mispaste guess.

1
6

but when I checked the duplicate, the question was about a python program skimming over some parts of a list.

That was, as far as I can tell, a clerical error by the person who closed the question. It is, however, absolutely a duplicate - that just wasn't the right link. It has since been fixed.

Fundamentally, what you are trying to do is not a sensible task, even if it is possible. It is harder than doing things properly, and will also make future steps in your program harder than they need to be. Instead, you should understand how to structure data properly, for example by using a dictionary or a list (or, for that matter, just keeping the data in the list that you already have). Instead of trying to have separate names to refer to the individual values, you should access elements of the list or keys of the dictionary, as appropriate. This is fully explained and elaborated in the now-linked duplicate Q&A. It's not a great Q&A, but it's the best we have been able to establish as a reference for the constant stream of such questions that we get. I would prefer if it were done over, with a question written by an expert, but inertia is hard to overcome.

You must log in to answer this question.