From: Michael P. S. <mso...@di...> - 2011-05-18 17:43:30
|
I find myself often doing this kind of thing trunks_by_remote_addr = {} for trunk in trunks: if not trunks_by_remote_addr.has_key(trunk[remote_addr]): trunks_by_remote_addr[trunk[remote_addr]] = [] trunks_by_remote_addr[trunk[remote_addr]].append(trunk) Now I have a dict, keyed by remote_addr of the trunk, with the values being a list of those using that address. I find the initial if check annoying. Can I do this in a better way? Thanks, Mike -- Michael P. Soulier <mso...@di...> "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein |