<br><br><div class="gmail_quote">On Fri, May 21, 2010 at 8:07 AM, Chad Kellerman <span dir="ltr"><<a href="mailto:sunckell@gmail.com">sunckell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><br><div class="gmail_quote"><div><div></div><div class="h5">On Fri, May 21, 2010 at 7:50 AM, Peter Otten <span dir="ltr"><__<a href="mailto:peter__@web.de" target="_blank">peter__@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<div>Chad Kellerman wrote:<br>
<br>
> Python users,<br>
>       I am parsing an AIX trace file and creating a dictionary containing<br>
> keys (PIDS) and values (a list of TIDS).  With PIDS being unique process<br>
> ids<br>
> and TIDS, being a list of thread ids.  My function populates the keys so<br>
> that they are unique, but my list contains duplicates.<br>
><br>
>      Can someone point me in the right direction so that my dictionary<br>
>      value<br>
> does not contain duplicate elements?<br>
><br>
><br>
> here is what I got.<br>
><br>
> --------------<portion of code that is relevant>------------------<br>
><br>
> pidtids  = {}<br>
><br>
> # --- function to add pid and tid to a dictionary<br>
> def addpidtids(pid,tid):<br>
>     pidtids.setdefault(pid,[]).append(tid)<br>
<br>
</div>Use a set instead of a list (and maybe a defaultdict):<br>
<br>
from collections import defaultdict<br>
<br>
pidtids = defaultdict(set)<br>
<br>
def addpidtids(pid, tid):<br>
    pidtids[pid].add(tid)<br>
<br>
Peter<br></blockquote></div></div><div><br>Thanks.  I guess I should have posted this in my original question.<br><br>I'm on 2.4.3  looks like defautldict is new in 2.5.<br><br>I'll see if I can upgrade.<br><br>Thanks again.<br>
</div></div></blockquote><div><br><br> instead of upgrading.. (probably be faster to use techniques in available 2.4.3)<br><br>Couldn't I check to see if the pid exists (has_key I believe) and then check if the tid is a value, in the the list for that key, prior to passing it to the function?<br>
<br>Or would that be too 'expensive'?<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote"><div>
<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<font color="#888888"><br>
--<div class="im"><br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></font></blockquote></div><br><br clear="all"><div><div></div><div class="h5"><br>-- <br>A grasshopper walks into a bar and the bartender says "Hey, we have a drink named after you." And the grasshopper says "Really, You have a drink named Murray?"<br>


</div></div></blockquote></div><br><br clear="all"><br>-- <br>A grasshopper walks into a bar and the bartender says "Hey, we have a drink named after you." And the grasshopper says "Really, You have a drink named Murray?"<br>