[Tutor] Keeping a list of attributes of a certain type

Guilherme P. de Freitas guilherme at gpfreitas.com
Fri Jan 15 21:43:30 CET 2010


Ok, I checked the answers you all gave me, and the suggestions seem to be 2:

a. Compute the list of members on the fly, with a list comprehension
that looks up stuff on self.__dict___;

b. Stay with my solution, but substituting the unnecessary "if-else"
by a simple "if". In sum, maintain a list of members that is updated
whenever a member is added or removed.

Which one is better? I am new to all this, so please correct me if I
am wrong. It seems that (a) is better if you do a lot of
adding/removing members operations compared to the number of lookups
to the "members" list. Otherwise, (b) is better. Right?

In my application, I will do many more lookups on the members list
than adding/removing members (this sounds weird, feels like I'm Dr.
Frankenstein), so I will go with (b).

Thanks again for all the suggestions,

Guilherme

-- 
Guilherme P. de Freitas
http://www.gpfreitas.com


More information about the Tutor mailing list