Use key instead of cmp for sorting.

All uses of `cmp=len_cmp` are replaced by `key=lexico_key`.  This is required for joint Python 2.x and 3.x compatibility.