Gaurav Tatke added the comment:

Hi,

Pardon my ignorance, I am new to this but have below queries/thoughts -

1. Why would we say that adding new keys during lookup phase is an unpleasant 
side-effect? From what I understood by docs, one of the main reasons to use 
defaultdicts is to be able to insert a missing key and give a default value to 
it. 'defaultdict' doc itself suggest that doing this is cleaner and faster than 
using dict.setdefault().

2. I believe defaultdict perfectly fits in this context of creating translation 
table for str.translate(). Even if we have very large string containing all 
characters from 4-5 languages, our defaultdict will still be comparatively 
small. It is easier to create a translation table using defaultdict when we 
have to strip most characters out of a string as in the example requested in 
the issue. Creating a translation table using str.maketrans() or by user 
defined function is tricky in this use case.

3. If argument for using defaultdict in this context is not convincing, shall I 
just give a patch, giving example of str.translate() using str.maketranse()?

Regards,

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28612>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to