0

I want to create variables names to be assigned to each index in the values list. So Result0 = 10, Result1 = 3, Result2 = 44, Result1 = 56601. Trying to code a function that creates and assigns variables depending on the length of the values list. The Code below does not work.

Code:

values = [10,3,44,56601]
k= 0
for n in values:
    Result{k} = n
    k+=1

Expected Result

Result0 = 10
Result1 = 3
Result2 = 44
Result3 = 56601
tony selcuk
  • 709
  • 3
  • 11

1 Answers1

0

As earlier posts, and @hulkinBrian pointed out similar case, this will be the approach: (credit to them all!)

dc = {}
for x in [10, 3, 44, 56601]:
    dc['Result{0}'.format(x)] = x

    
Daniel Hao
  • 4,922
  • 3
  • 10
  • 23