Often a good way to do it (depending what you're trying to achieve) is to create a dictionary before the loop and then use whatever loop variable you want as the key for the dictionary. This is generally better than using eval IMHO. You also don't need to have a string as the key but can have any immutable type Eg an integer or a tuple.
Comment