Skip to content
Advertisement

Output variable names when summing a tuple

A list of variables with assigned values. I want to return all the possible combinations from each pair (every two of them).

The print-out is the names of the pair, and sum of them.

For example:

JavaScript

I’ve tried below. The result comes out, but not the names of pairs:

JavaScript

What’s the right way to do it?

Advertisement

Answer

If you use a dict instead of named variables, you can easily convert the names themselves into the int values via dictionary lookups.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement