Python variable expansion

I have the following in Python:

D1rms1 = function(G1, selection=str(value1))

and I have to make 5 of these, where each time the only thing that changes is the number.
If I were using bash, I would do something like this:

for i in {1..5}; do
name${i}=value${i}
done

All I can find is shit about f-strings. I have asked people that use Python everyday; no luck.
I thought Python was supposed to be a "proper" scripting language, WTF.
Is there anyway I can put the above in a loop, like in bash?

Attached: Python-for-loop.png (1200x900, 88.35K)

Use an array, retard.

Did you try these wild new things called arrays? Python should support them

How are these Gn and valuen's are generated? They should have been in an array in the first place. Still, you can put them in arrays, like Gs = [G1, G2, ...] and values = [value1, value2, ..]. And call the function like for G, value in zip(Gs, values): ... If you still want to do it the way you explained, you can use locals() and globals() dicts

They are strings/integers defined manually.
Thank you for the recommendation, but it is not only the right part that has numbers that change, there is also the variable name D1rms1 and this is actually the thing I cannot find out, cause I cannot assign to a list element for example.

Make the variable d1rms, make it be an array, and index it as d1rms[0], d1rms[1], etc...

How will this create
D1rms1 = function(G1, selection=str(value1))
D2rms2 = function(G2, selection=str(value2))
D3rms3 = function(G3, selection=str(value3))
etc? I need all the numbers to change (there are 2 numbers in the variable name).

Stop putting numbers in your fucking variable names. This is a clear sign that you need to be using lists or dicts

Good morning sir

>D1rms1 = function(G1, selection=str(value1))
>and I have to make 5 of these, where each time the only thing that changes is the number.
what is "the" number

numbers = [1,2,3]
for x in numbers:
somebullshit(x)

???

Lmao

eval()

Attached: 1634213510160.jpg (828x803, 512.06K)

The numbers are important in showcasing what the variable is about. Also, if they have totally different names, then I would have to select one name and keep ovewriting it (in order to be able to put it in a loop)? So:
for i in range(1,6):
varname = function(Gs[i-1])

Is there no straightforward way, like in the bash example?

dont listen to all of the stackoverflow niggers in the thread. i am here to help
# change range to be how many variables you want to be set
for i in range(10)
exec(f"D{i}rms{i} = function(G{i}, selection=str(value{i}))")

Attached: facepalm.gif (220x220, 842.59K)

i have no idea what are you trying to achieve but:

def function(G, val):
return G, val

for i in range(5):
vars()['D'+str(i)+'rms'+str(i)] = function(i,str(i))

print(D0rms0)
print(D4rms4)

good morning kind sirs

FFS, I'm european; this is just the first time using Python and I couldn't find anything like the bash example, even after talking to Python users, as I stated. Not a programmer, not claimming to be one, I just need to use a bit of Python.

you technically can use eval and exec to hack together something like you're saying, but this is really not the way python is written. use lists for this. for instance, suppose you have a list of values and a list of Gs, both with length 5, you'd do something like:

Drms = []
for val, G in zip(values, Gs):
Drms.append(function(G, selection=str(val)))

The "1" needs to be changing in every occurence in the line, but everything else must be staying the same.

The issue is making:
name1 = stuff(G1)
name2 = stuff(G2)
The name1, name2 etc is what I cannot generate on the spot in a loop and assign to them.

If you think this is straightforward, please translate the bash loop to Python.

>Is there no straightforward way, like in the bash example?
The straightforward way, which would be used in EVERY LANGUAGE OTHER THAN FUCKING BASH is to use an array or a hash table. Bash is unique in that it doesn't have types, so it lets you fuck around with variable names in weird ways as an ugly hack to make up for it.

The design pattern you seem to be trying to use is bad. You keep asking us how to use a language's ugly bad hack in another language that doesn't need that hack, and we keep telling you to use a better design. You refuse to use a better design.

And by the way, what the FUCK kind of variable name is D1rms1? There are no goddamn vowels in that shit, and it's not a one letter variable name with an obvious purpose. Why the hell do you insist on making unreadable garbage?

your answer is already posted, fat gorilla nigger

names = []
for G in Gs:
names.append(G)

numbers = [1,2,3]
for x in numbers:
globals()["Some" + x + "bullshit"] = somebullshit(x)

lol based