def _sort_kw_matches(skw_matches, limit=0):
    """Return a resized version of keywords to the given length."""
    sorted_keywords = list(skw_matches.items())
    sorted(sorted_keywords, key=cmp_to_key(_skw_matches_comparator))
    return limit and sorted_keywords[:limit] or sorted_keywords