0

I´m kind of new to Prog. and I need help transforming a list of symbols to a set of variables with the same names so that I can assign values to them. Zero idea what to do.

Here at the two lists, one for the symbols and the other for the results

Vars = [Mmj, Mj1, Mj2, Mj3, Mj4, Mj5, Mj6, Mbmj, Mbj1, Mbj2, Mbj3, Mbj4, Mbj5, Mbj6, Mfmj, Mfj1, Mfj2, Mfj3, Mfj4, Mfj5, Mfj6, Mb1, Mb2, Mb3, Mb4, Mb5, Mb6, Mfb1, Mfb2, Mfb3, Mfb4, Mfb5, Mfb6, Mbb1, Mbb2, Mbb3, Mbb4, Mbb5, Mbb6, Mcc, Mfcc, Mbcc]
Ans = [287.36, 276.19, 95.042, 84.266, 56.562, 40.971, 26.053, 55.910, 50.825, 18.681, 11.380, 7.2471, 4.4876, 5.5152, 1.2431, 7.7696, 7.7694, 7.7681, 7.7570, 7.6627, 6.8581, 205.68, 194.91, 167.20, 151.61, 136.69, 228.85, 66.226, 66.225, 66.214, 66.120, 65.315, 58.457, 26.451, 19.150, 15.017, 12.258, 13.285, 7.7702, 83.870, 14.296, 13.595]

I tried doing:

for i in range(len(Vars)):

    Vars[i] = Ans[i]

but it just replaced the each symbol by the value.

wwii
  • 23,232
  • 7
  • 37
  • 77
  • 1
    Also, your `Vars` list isn't valid - aren't the values supposed to be strings? They should be in quotes, then. – Thierry Lathuille Sep 25 '19 at 18:06
  • Please format the code and data: select it and type `ctrl-k`. [Formatting help](https://stackoverflow.com/help/formatting) ... [more Formatting](https://stackoverflow.com/editing-help) ... [Formatting sandbox](https://meta.stackexchange.com/questions/3122/formatting-sandbox) – wwii Sep 25 '19 at 18:08
  • A common solution is to create a dictionary - use `Vars` for the keys. – wwii Sep 25 '19 at 18:11

1 Answers1

0

Assuming I understand what you're trying to do, you need to create a new list or dictionary.

Here's how you could do it with a dict.

Pairs = {}

for i in range(len(Vars)):
    pairs[Vars[i]] = Ans[i]

Evan Lalo
  • 1,209
  • 1
  • 14
  • 34