Try:
lst = ['hello', '3', 'apple', 'boy', '2', 'ball', 'play', '6'] lst_pos = [item.isalpha() for item in lst] print(lst_pos) # [True, False, True, True, False, True, True, False] lst_str = sorted(item for item in lst if item.isalpha()) print(lst_str) # ['apple', 'ball', 'boy', 'hello', 'play'] lst_num = sorted(item for item in lst if not item.isalpha()) print(lst_num) # ['2', '3', '6'] new_lst = [] for value in lst_pos: if value: new_lst.append(lst_str.pop(0)) else: new_lst.append(lst_num.pop(0)) print(new_lst) # ['apple', '2', 'ball', 'boy', '3', 'hello', 'play', '6']
helloafterplay? - andreymal