Linked Questions

233 votes
8 answers
625k views

I want to create variables dynamically in Python. Does anyone have any creative means of doing this?
Noah R's user avatar
  • 5,477
0 votes
3 answers
2k views

I'm working on a python program where it asks the user for input and then creates a variable with the same name as the user output, like this: Input: Hello And then it creates a new variable called ...
Lost in code's user avatar
0 votes
2 answers
166 views

EDIT: This is not a duplicate question. The answer received here actually creates new variables/objects inside the program. That this may or may not be what is actually best for me is immaterial. ...
Mr. A's user avatar
  • 229
0 votes
2 answers
100 views

If I have an array Numbers = [1, 2, 3] and a loop that depend on these numbers and inside the loop I have and a dictionary or some object that I want to name with the numbers in the array Numbers, how ...
Joseph Clifford's user avatar
-1 votes
1 answer
76 views

I am new to Python, and I have no idea how to do this. Any help would be greatly appreciated. I have 2 files that I am reading in : yesterday's people list and today's people list I am attempting to ...
mixingbuddha's user avatar
168 votes
3 answers
455k views

I have any string. like 'buffalo', x='buffalo' I want to convert this string to some variable name like, buffalo=4 not only this example, I want to convert any input string to some variable name. ...
Harshitha Palihawadana's user avatar
8 votes
2 answers
3k views

I have a list of strings such as: names = ['apple','orange','banana'] And I would like to create a list for each element in the list, that would be named exactly as the string: apple = [] ...
user1962851's user avatar
8 votes
3 answers
11k views

Is it possible to create a local variables with Python code, given only the variable's name (a string), so that subsequent calls to "'xxx' in locals()" will return True? Here's a visual : >>&...
MitchellSalad's user avatar
0 votes
3 answers
8k views

I want to use some code similar to what follows that actually works: P = 20 n = 1 for x in range(1, P+1): Ax = n #Hoping that you can name the variable from the current element in the range n ...
D Rayner's user avatar
-1 votes
5 answers
6k views

suppose I have lists of strings like this list1 = ["x","y","z"] so how can create empty dictionaries like x = {}, y = {} and z = {} by iteration Following method does nothing: for i in list1: ...
Saurabh's user avatar
  • 1,692
0 votes
3 answers
2k views

Is there some easy way to access an object in a list, without using an index or iterating through the list? In brief: I'm reading in lines from a text file, splitting up the lines, and creating ...
user2454099's user avatar
2 votes
3 answers
464 views

This is poor programming practice, yes, I know, but these scripts are purely mine and this technique would ease my coding a lot. Right now, I have an SQLite database containing a set of key-value ...
mngeek206's user avatar
  • 5,227
-1 votes
1 answer
1k views

I need to create multiple variables based on int input so that if input is 5 then variables are created like: worker1, worker2, worker3, etc. Is there any way in which I could generate variables like ...
muchuu17's user avatar
0 votes
3 answers
119 views

Im trying to create a function that takes a list and assigns each of the strings in the list to a variable even when you dont know how many strings are in the list Here is something i tried: ...
Serial's user avatar
  • 8,051
1 vote
3 answers
365 views

I have an application that reads multiple variable names from one block of an input file. Then it reads the associated values from another block of the same file.. e.g. variable names read in as ABC,...
Kevin Karney's user avatar

15 30 50 per page