import re


def num_sort(x, inf=float('inf')):
    """A sort key function to sort strings by a numeric prefix, then
    lexically.
    """
    if not isinstance(x, str):
        return (0, x)
    m = re.match(r'[\d.-]+', x)
    try:
        return (float(m.group()), x) if m else (inf, x)
    except ValueError:
        return (inf, x)