Referring to a list
Larry Bates
lbates at swamisoft.com
Fri Jun 25 17:56:02 EDT 2004
Absolutely. Everything in Python is a pointer.
x=final_list
is a pointer to final_list
x=final_list_other
changes what x points to.
Larry Bates
Syscon, Inc.
"Sean Berry" <sean_berry at cox.net> wrote in message
news:1a0Dc.13333$rh.4819 at okepread02...
> 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