On Fri, 25 Jul 2008 17:05:27 -0400, Terry Reedy wrote: > If the nodes do not have to be processed in any particular order, then > you could keep them either in a dict, with the value being either On or > Off (True,False)(plus connection data) or a pair of sets, one for On and > one for Off. The advantage of the dict is that the items would be fixed > and only their values would change, but you needlessly scan through On > items. The advantage of the set pair is that you only scan through Off > items but have to move some from Off to On. I will not guess which > would be faster over a complete run, or how this will compare with using > lists. > > tjr
Thanks for the reply. As mentioned in my original post, sets came to mind straight way, doing it the way you suggest. I alluded to, but didn't directly ask: Since I am doing A LOT of loops over the nodes and the number of nodes is also huge, my concern using sets is that in order to iterate over the set in each step of my simulation, the set items need to be converted to a list every time. So while removal from a set is much cheaper than say from a list, what about this conversion overhead in order to iterate over the items. The dict suggestion is good. Originally I had my nodes as objects, with a networkx object for the graph (which is a dict). Since efficiency is the most important this for this piece of code, I may decide to forget about abstract nodes and put all attributes in a dict as you suggest. Too many permutations, which is why I made the original post, hoping wiser python coders could eliminate a few possibilities. :) -- http://mail.python.org/mailman/listinfo/python-list