use key param to support instead of cmp for compatibility across python versions