Write a Python Program to Sort Each Sublist Of Strings in Given List Of Lists

Write a python program to sort each sublist of strings in a given list of lists is provided on this page.

Write A Python Program To Sort Each Sublist Of Strings In A Given List Of Lists

In this program we use the function sorted() to sort a list.

We use the function map() to pass or map the values of list to function sorted() so that it can sort those values then we convert the result into list.

Finally we use the function and call it by passing names list.


def sort_sublists(input_list):
    result = list(map(sorted, input_list)) 
    return result


names = [["john", "dwayne"], ["rock", "cena"], ["robert", "chris", "mark"]]

print("Original list : ")
print(names)


print("\nAfter sorting each sublist of list of lists : ")
print(sort_sublists(names))

Related To Python

Comments