Reputation: 55
I have a program that calls a function, and the function returns an integer within a range of 1-25. I have a corresponding 25 lists in my program that, based on the value of this returned integer, I then need to pass to another function.
For example:
List1 = [1, 45]
...
List25 = [4, 584]
def ReturnListRef():
a = 24
return a
What would be the quickest way to use the returned value of '24' to send List24 to my next function?
Seems like it should be so easy to do, but after finishing up my beginners guide to Python book, I still can't achieve this without what seems like too many steps!
Upvotes: 1
Views: 87
Reputation: 180441
Use a dict to store your lists:
d = {24:[1, 45],25:[4, 584]}
def ReturnListRef():
a = 24
return a
def foo():
var = d[ReturnListRef()]
print var
print foo()
[1, 45]
Upvotes: 2