
Python IAQ: Infrequently Answered Questions - dpritchett
http://norvig.com/python-iaq.html?a
======
etal
It's cool how many of these kludges are fixed in more recent Pythons,
especially Python 3 (and its features backported to 2.6 and 2.7):

Q3. _Polymorphism, and the lack of sequence and number types_ \-- there are
now abstract base classes for Iterable and Number types, etc.

Q6. _printf function_ \-- print() is indeed a function in Python 3

Q8. _object syntax shortcut_ \-- collections.namedtuple in Py2.6 is similar,
acting something like a factory for anonymous classes

Q9. _syntax for updating objects_ \-- in recent Pythons, this works:
obj.__dict__.update(foo=1, bar=2)

Q10. _dictionary with default values_ \-- collections.defaultdict

Q13. _abstract base classes_ \-- hilarious, but now there's a decorator in the
abc module that does the right thing

Q18. _missing queue types_ \-- collections.deque is a good double-ended queue,
and the heapq module can turn a list into a heap queue.

You can also see how many of his other wish-list items came true, especially
via the itertools module, in his personal 'utils' module:

<http://aima.cs.berkeley.edu/python/utils.html>

~~~
koenigdavidmj
You can also say a_dict.setdefault(key, default) which is like a_dict.get(key,
default) but will also do a_dict[key]=default if there does not already exist
a value for key.

------
jcl
A funny little bit of snark hidden in the middle, following some decidedly
unpythonic code:

 _If u cn rd ths, u cn gt a jb in fncnl prg (if thr wr any)._

~~~
sketerpot
The code preceding that is actually pretty simple if you translate it to
Haskell:

    
    
        my_if test result alternative = if test then result else alternative
    

It's just trying to get currying and lazy evaluation in Python which causes
all the ugliness.

------
kingkilr
Unfortunately it's quite old, and some of the answers are rather out of date.

~~~
dpritchett
It appears you're right! I can't find a date on Norvig's site but here's a
link to it from 2001: <http://www.brokenrobot.org/archives/000427.html>

~~~
jcl
Norvig did some curation over the years, however. One of the answers mentions
that the ternary "if" expression is scheduled to appear in Python 2.5, which
is information from around 2006.

