Fix Python – Seeing escape characters when pressing the arrow keys in python shell

In shells like the interactive python shell, you can usually use the arrow keys to move around in the current line or get previous commands (with arrow-up) etc.
But after I ssh into another machine and start python there, I get sessions like:
>>> import os
>>> ^[[A

where the last character comes from arrow-up. Or, using arrow-left:
>>> impor….

Fix Python – Create a list with initial capacity in Python

Code like this often happens:
l = []
while foo:
# baz
l.append(bar)
# qux

This is really slow if you’re about to append thousands of elements to your list, as the list will have to be constantly resized to fit the new elements.
In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will ….