Linked Questions
52 questions linked to/from generating variable names on fly in python
566
votes
19
answers
282k
views
How do I create variable variables?
I know that some other languages, such as PHP, support a concept of "variable variable names" - that is, the contents of a string can be used as part of a variable name.
I heard that this is ...
0
votes
3
answers
2k
views
How to create multiple turtles in a for loop? [duplicate]
Let's say I want to create multiple turtles but also let the user decide how many there is. Is there a way to make a code like this? :
n = input()
for i in range(n):
'turtle' + i = Turtle()
So ...
0
votes
0
answers
2k
views
Change name of dictionary or list in a loop [duplicate]
So I have something like this:
for j, key in zip(range(10), SomeNestedDictionary.keys()):
dictionary1 = SomeNestedDictionary[key]
However here dictionary1 , is always the same name. Instead I ...
0
votes
0
answers
303
views
Convert each dictionary key-value into dataframe- Pandas [duplicate]
I have a dictionary that contains 6 dataframes stored as values. I'd like to convert these values into actual dataframes with the name of the dataframe being the key corresponding to the values. The ...
0
votes
1
answer
205
views
Python Looping Through Lists and Creating Dynamic Variables [duplicate]
I am looping through elements of lists that vary in length and content. Here is the object (keys) that I use:
keys:
key dims
1 ['site', 'channel', 'fiscal_week']
2 [...
0
votes
0
answers
189
views
Recalling a certain number of lists Python 3 [duplicate]
I am working on a program that store information in different lists using globals. The numer of lists changes everytime the program runs.
I want to use the data stored in those lists but don't know ...
0
votes
1
answer
129
views
one class for each string in list in python [duplicate]
Let's suppose I have a list of strings:
people = ['Mike','Paul','Caroline']
and a class:
class Person:
def __init__(self, name, is_married = False):
self.name = name
self....
0
votes
1
answer
85
views
how to avoid if..then for elements in a long list of counters [duplicate]
I have a list of counters in my code and if it is possible I'd like to avoid to write an if condition for each of them.
I figured out the following solution in python 3, but it doesn't works.... how ...
0
votes
1
answer
107
views
Python how do I assign some data to a variables value [duplicate]
Code snippet:
data = [("a", "b", "c", "d"),("e", "f", "g", "h")]
for i in data:
console = '{}_{}'.join(('consoleip',str(i[2])))
<> = Hostdata(hw_id = i[0],location_id = i[1],consoleip = ...
0
votes
1
answer
59
views
Iterate over list then use list item to build name to perform task [duplicate]
sorry for the confusing title, I am unsure of what I am asking but I should be able to explain it better.
I have a list of items
list = ['s1',s2','s3']
I am iterating of the list no worries:
for l ...
2
votes
1
answer
70
views
Is it possible to generate dynamic objects x times [duplicate]
I would like to get a number from the user lets say 3.
Now i want to create objects with the name 'user1 = User() , user2 = User(), user3 = User()'
is that possible at all?
or is there an ...
0
votes
2
answers
65
views
Returning a list from a function with many lists in it [duplicate]
Noob question ahead
So I am making a basic text-based RPG just to get me back into the basics of Python after being gone for a few months.
I'm trying to make a function that has all of the items in ...
-1
votes
2
answers
69
views
Why isn't the input function working? [duplicate]
I started making a project that is showing which bands I like, then ask what artist/band's albums they want to see rated by me. I've got it to show what albums I like but then whenever I try to get ...
0
votes
1
answer
63
views
Changing a list name variable in a for loop [duplicate]
judges = ["judge 1", "judge 2", "judge 3", "judge 4", "judge 5",]
couples = [1, 2, 3, 4, 5]
x=0
j=0
done = False
def judging(j, x, judges, couples,):
couplescores1 = []
couplescores2 = []
...
-3
votes
1
answer
55
views
Trying to make the user choose an option but it isn't working [duplicate]
So user should choose between A, B or C and it should put that value into the random int
Error message: ValueError: invalid literal for int() with base 10: 'A'
option=input()
A=a=100
B=b=150
C=c=...