in this article we'll write an example which get the the longest word in string

example


#string
string = "Python is a great langauge"

#split string
str_list = string.split()

#sort list by lenght
list_s = sorted(str_list, key=len) 

#print the lats item of list
print(list_s[-1])

output

langauge

as you can see "language" is the longest word in the string.



so in the example above we have used sorted() function.

The sorted() function sorts the elements of a given iterable in a specific order.

English today is not an art to be mastered it's just a tool to use to get a result