Run
def myFunc(x): if isinstance(x, str): return len(x) else: return x nums = [2, 8, 1, 7, 'apple', 'watermelon'] nums_sorted = sorted(nums, key = myFunc) print(nums_sorted)
Output