0

[SOLVED] How can i make a variable changes its name according to the iteration of the for loop??

Python Loops Variables

16th Feb 2020, 7:03 PM
AbdErrazak Kenniche
AbdErrazak Kenniche - avatar
5 Respostas
+ 1
Variable's names usually don't change at all. Can you tell us more about what you're trying to do? Maybe we know another solution to what you want to do. Also, why is this about Java, JS and Python?
16th Feb 2020, 7:08 PM
HonFu
HonFu - avatar
+ 2
Is this for Python, Javascript, or Java? Multiple tags are useless and need to be removed for clarification.
16th Feb 2020, 7:09 PM
Jianmin Chen
Jianmin Chen - avatar
+ 1
How about using a dictionary? There you can store something (also a list) under a key. nums = [7, -5, 3] stuff = {} for n in nums: stuff[n] = [float(n), abs(n), str(n)] print(stuff[-5]) Try this. You basically only need to change what you store under each key (your calculation).
16th Feb 2020, 7:51 PM
HonFu
HonFu - avatar
0
In python I have a list of numbers Using for loop am ganna create lists which contains divisors of each num. At the end i want to combine them then get the maximum as the gcd of those nums What it needs is to change the name of the list according to the num.
16th Feb 2020, 7:14 PM
AbdErrazak Kenniche
AbdErrazak Kenniche - avatar
0
Yh it seems right!
16th Feb 2020, 7:53 PM
AbdErrazak Kenniche
AbdErrazak Kenniche - avatar