Hi Richard,<br><br>I&#39;ve always used such things with some caution. I work with a lot of people who are probably not aware of many of the libraries in Python. For that reason, I try to stick to the standard dict. Calling setdefault is a good hint to a Python newbie that something particular is &#39;going on&#39; and that they should look it up. However, if you pass in an object, it might not be clear that something is a defaultdict rather than a regular dict, and it could be easy to lose track of when you are allowed to use defaultdict functionality.<br>
<br>It seems a bit kinder to me on new programmers and team members not to use defaultdict.<br><br>I think ideally I&#39;d like the standard dict to accept another argument, i.e.<br><br>myDict[&quot;fruit&quot;, []].append(banana)<br>
<br>Cheers,<br>-T<br><br><div class="gmail_quote">On Mon, Aug 17, 2009 at 2:30 PM, Richard Baron Penman <span dir="ltr">&lt;<a href="mailto:richardbp@gmail.com">richardbp@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">&gt; I always wish setdefault looked a little nicer, but it&#39;s such a great defensive programming technique that I just use it anyway.<br><br></div>instead of setdefault you can often use defaultdict:<br>
<br>&gt;&gt;&gt; from collections import defaultdict<br>

&gt;&gt;&gt; d = defaultdict(list)<br>&gt;&gt;&gt; d[&#39;fruit&#39;].append(&#39;apple&#39;)<br>&gt;&gt;&gt; d[&#39;fruit&#39;].append(&#39;banana&#39;)<br>&gt;&gt;&gt; print d[&#39;fruit&#39;]<br>[&#39;apple&#39;, &#39;banana&#39;]<br>
<font color="#888888">

<br>Richard</font><div><div></div><div class="h5"><br><br><br><br><div class="gmail_quote">On Mon, Aug 17, 2009 at 1:15 PM, Tennessee Leeuwenburg <span dir="ltr">&lt;<a href="mailto:tleeuwenburg@gmail.com" target="_blank">tleeuwenburg@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Cool, I didn&#39;t know about maketrans. Thanks.<br><br>I always wish setdefault looked a little nicer, but it&#39;s such a great defensive programming technique that I just use it anyway.<br><br>Thanks for kicking the discussion off, M. Nice to see some chatter on the list at last! :)<br>



<br>Cheers,<br>-T<div><div></div><div><br><br><br><div class="gmail_quote">On Mon, Aug 17, 2009 at 1:09 PM, John La Rooy <span dir="ltr">&lt;<a href="mailto:john.larooy@gmail.com" target="_blank">john.larooy@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This is how I would do it.<br>
<br>
#!/usr/bin/env python<br>
from string import maketrans<br>
<br>
dictionary = &quot;sowpods.txt&quot;<br>
nokia = maketrans(&quot;abcdefghijklmnopqrstuvwxyz&quot;,&quot;22233344455566677778889999&quot;)<br>
<div>phononyms = {}<br>
<br>
for word in open(dictionary):<br>
</div>    word = word.strip().lower()<br>
    phononyms.setdefault(word.translate(nokia), []).append(word)<br>
<br>
for k,v in phononyms.iteritems():<br>
    if len(v) &gt; 1:<br>
        print v<br>
_______________________________________________<br>
melbourne-pug mailing list<br>
<a href="mailto:melbourne-pug@python.org" target="_blank">melbourne-pug@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/melbourne-pug" target="_blank">http://mail.python.org/mailman/listinfo/melbourne-pug</a><br>
</blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br>--------------------------------------------------<br>Tennessee Leeuwenburg<br><a href="http://myownhat.blogspot.com/" target="_blank">http://myownhat.blogspot.com/</a><br>


&quot;Don&#39;t believe everything you think&quot;<br>

</font><br>_______________________________________________<br>
melbourne-pug mailing list<br>
<a href="mailto:melbourne-pug@python.org" target="_blank">melbourne-pug@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/melbourne-pug" target="_blank">http://mail.python.org/mailman/listinfo/melbourne-pug</a><br>
<br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
melbourne-pug mailing list<br>
<a href="mailto:melbourne-pug@python.org">melbourne-pug@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/melbourne-pug" target="_blank">http://mail.python.org/mailman/listinfo/melbourne-pug</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>--------------------------------------------------<br>Tennessee Leeuwenburg<br><a href="http://myownhat.blogspot.com/">http://myownhat.blogspot.com/</a><br>&quot;Don&#39;t believe everything you think&quot;<br>