Referring to a list

Russell Blau russblau at hotmail.com
Fri Jun 25 17:12:34 EDT 2004


"Sean Berry" <sean_berry at cox.net> wrote in message
news:1a0Dc.13333$rh.4819 at okepread02...
> 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???

Does this help?

>>> odd_list = []
>>> even_list = []
>>> def which_list(x):
      if x % 2 == 0:
          return even_list
      else:
          return odd_list

>>> for i in range(20):
      which_list(i).append(i)


>>> odd_list
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
>>> even_list
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]


-- 
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.





More information about the Python-list mailing list