Linked Questions

210 votes
9 answers
699k views

For example purposes... for x in range(0,9): string'x' = "Hello" So I end up with string1, string2, string3... all equaling "Hello"
Takkun's user avatar
  • 8,769
233 votes
8 answers
626k 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
186 votes
3 answers
512k views

I have a variable with a string assigned to it and I want to define a new variable based on that string. foo = "bar" foo = "something else" # What I actually want is: bar = &...
9-bits's user avatar
  • 10.8k
48 votes
8 answers
110k views

How can I make many empty lists without manually typing the following? list1=[], list2=[], list3=[] Is there a for loop that will make me 'n' number of such empty lists?
Sameer Patel's user avatar
122 votes
7 answers
105k views

How do you dynamically set local variable in Python (where the variable name is dynamic)?
Jonathan Livni's user avatar
78 votes
6 answers
145k views

Is there a way I can generate variable names in python in a loop and assign values to them? For example, if I have prices = [5, 12, 45] I want price1 = 5 price2 = 12 price3 = 45 Can I do this in a ...
Curious2learn's user avatar
39 votes
7 answers
168k views

if I have a list, say: ll = ['xx','yy','zz'] and I want to assign each element of this list to a separate variable: var1 = xx var2 = yy var3 = zz without knowing how long the list is, how would I do ...
David Yang's user avatar
  • 2,171
45 votes
3 answers
172k views

I have multiple (more than 100) dataframes. How can I concat all of them? The problem is, that I have too many dataframes, that I can not write them manually in a list, like this: >>> ...
PParker's user avatar
  • 1,519
41 votes
5 answers
227k views

I was just wondering if anyone knew of a way to change variable names based off of a for loop for something like this: for i in range(3) group+i=self.getGroup(selected, header+i) so that the ...
user130633's user avatar
  • 2,313
22 votes
5 answers
97k views

How do I use a loop to name variables? For example, if I wanted to have a variable double_1 = 2, double_2 = 4 all the the way to double_12 = 24, how would I write it? I get the feeling it would be ...
davenz's user avatar
  • 399
15 votes
5 answers
38k views

I am currently writing a Python script to handle some logs and reformat certain parts. Part of the script makes use of the following code (as an example): var1,var2,var3=foo.split("|") ...
MHibbin's user avatar
  • 1,185
19 votes
7 answers
47k views

I'm aware I can assign multiple variables to multiple values at once with: (foo, bar, baz) = 1, 2, 3 And have foo = 1, bar = 2, and so on. But how could I make the names of the variables more ...
mikemaccana's user avatar
16 votes
4 answers
85k views

In Python, if I were to have a user input the number X, and then the program enters a for loop in which the user inputs X values, is there a way/is it a bad idea to have variable names automatically ...
tom's user avatar
  • 161
10 votes
6 answers
75k views

I'm trying to create multiple lists like the following: l1 = [] l2 = [] .. ln = [] Is there any way to do that?
Sathish Bowatta's user avatar
8 votes
2 answers
95k views

I've been playing with Python and I have this list that I need worked out. Basically I type a list of games into the multidimensional array and then for each one, it will make 3 variables based on ...
Skowt's user avatar
  • 411

15 30 50 per page
1
2 3 4 5
100