Message284342
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, |
|
Date |
User |
Action |
Args |
2016-12-30 20:15:33 | Gaurav Tatke | set | recipients:
+ Gaurav Tatke, rhettinger, docs@python, Jim.Jewett, serhiy.storchaka, ChrisBarker |
2016-12-30 20:15:33 | Gaurav Tatke | set | messageid: <1483128933.67.0.601009793562.issue28612@psf.upfronthosting.co.za> |
2016-12-30 20:15:33 | Gaurav Tatke | link | issue28612 messages |
2016-12-30 20:15:33 | Gaurav Tatke | create | |
|