Referring to a list

Sean Berry sean_berry at cox.net
Fri Jun 25 16:42:38 EDT 2004


I have a function like this:

final_list = []

def doSomething():
    for item in starting_list = []:
        Do all sorts of stuff... about 150 lines of processing.
        Lots of conditional statements for appending to the final_list.
            So I have lots of final_list.append( results ) statements.

I wanted to single out a few cases and have
them append to a different list.

The way I would "normally" do something like this would be to have
all of the .append() statements in another function like this

def addToList( listName, otherInfo )
    do something with otherInfo.
    then listName.append( results )

But, in this case, by the time I get to this point there
are too many variables to pass (something like 60).

So, what I want to do is use some kind of name reference
for the list I want to use.

EXAMPLE:
final_list = []
secondary_list = []

def DoSomething():
    if (condition is met):
        list_i_am_referring_to = final_list
    else
        list_i_am_referring_to = secondary_list

then I can do everything using the list_i_am_referring_to.

Is this possible???

Sorry about my poor, and lengthy explanation.
Thanks for any help.





More information about the Python-list mailing list