+ 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
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
+ 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.
+ 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
+ 4
JUMP_LINK__&&__Python__&&__JUMP_LINK Learner Ipang Aleksei Radchenkov Thanks guys for making it clear ☺