Q:

Write a Python program to sort a given mixed list of integers and strings. Numbers must be sorted before strings

0

Write a Python program to sort a given mixed list of integers and strings. Numbers must be sorted before strings

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def sort_mixed_list(mixed_list):
    int_part = sorted([i for i in mixed_list if type(i) is int])
    str_part = sorted([i for i in mixed_list if type(i) is str])
    return int_part + str_part
mixed_list = [19,'red',12,'green','blue', 10,'white','green',1]
print("Original list:")
print(mixed_list)
print("\nSort the said  mixed list of integers and strings:")
print(sort_mixed_list(mixed_list))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now