May-28-2020, 01:23 PM
as already said - use proper data structure
# sources is a tuple sources=(0.1, 0.2, 0.3) # access elements in tuple/list by index print(sources[0]) print(sources[2]) # you can assign to a name foo = sources[1] # use that name print(foo) # using dict, created with dict comprehension spam = {f'a{idx}':num for idx, num in enumerate(sources)} print(spam) # access elements by key print(spam.get('a0')) print(spam['a1']) print(spam.get('a5', 'wrong key')) # using dict, created another way spam = {} for idx, num in enumerate(sources): spam[f'a{idx}'] = num print(spam) # access elements by key print(spam.get('a0')) print(spam['a1']) print(spam.get('a5', 'wrong key'))
Output:0.1
0.3
0.2
{'a0': 0.1, 'a1': 0.2, 'a2': 0.3}
0.1
0.2
wrong key
{'a0': 0.1, 'a1': 0.2, 'a2': 0.3}
0.1
0.2
wrong key
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs