+ 2

Check the program

text = ("Welcome to the jungle") x = text.split() print(x) y = (max(x)) print(y) Output ['Welcome', 'to', 'the', 'jungle'] to Why Welcome is not the result ? Explain

3rd Oct 2021, 1:39 PM
Sayyam Jain
Sayyam Jain - avatar
4 ответов
+ 5
The Python max() function returns the largest value in an iterable, such as a list. If a list contains strings, the last item alphabetically is returned by max(). If you want your program to return the longest string in the list you could do it as follows: https://code.sololearn.com/chqca5OF1wwy/?ref=app
3rd Oct 2021, 1:44 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 5
Because lexicographically, "to" is greater than "the", "jungle" and "Welcome". To understand this, you might wanna lookup on ASCII code of each letters in each word.
3rd Oct 2021, 2:04 PM
Ipang
+ 5
It's better to say ascii value instead of alphabetical order. Because special characters(@,#,$,&,:...) don't have alphabetical order. So, lexycographically means it compares ASCII value of character and compare which character has higher ASCII value , for example "a"(97) has higher ASCII value than "A"(65). Here, you have two "t"s. So, it checks the next letter and so on. You can check this code to understand this concept clearly. https://code.sololearn.com/cC9WgmCo21ca/?ref=app
3rd Oct 2021, 2:24 PM
Python Learner
Python Learner - avatar
3rd Oct 2021, 2:28 PM
Sayyam Jain
Sayyam Jain - avatar