1

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!

5
  • 4
    You know you can have a list of a list, too? items = [[1, 45], [...], ..., [4, 584]]. With that you simply return items[a] Commented Jul 29, 2014 at 11:49
  • 3
    Keep data out of your variable names Commented Jul 29, 2014 at 11:51
  • items = [[1, 45], [...], ..., [4, 584]] then you can return items[24] Commented Jul 29, 2014 at 11:51
  • Aye, I simplified the above a little (lot). Each of the lists is pulled from a class and contains multiple lists. Commented Jul 29, 2014 at 11:53
  • You can have lists of lists of lists too. You can have any level of nesting you want, and the fact that the lists were pulled from a class (whatever you precisely meant by that, because it's not clear) won't interfere with sticking them in another list. Commented Jul 29, 2014 at 12:02

1 Answer 1

2

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Exactly what I'm after.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.