+ 2
What does "key=len" default variable do in this line of code ?
words =[ "hi","solo"] more = [x*len(x) for x in words] print(len(max(more,key =len))) '''without key=len ooutput is same then why to use this default variable'''
2 Réponses
+ 4
because 'solo' > 'hi' returns True. You will probably understand the difference if you compare 'aaaa' and 'bb'
+ 3
you can use the max method according to your need.max method use for find the maximum value in your list,set etc.but remeber that maximum value which you are finding can be compare two integers it can be the length of two strings which you are comparing etc.here max use for compare the length of two strings and key is telling to the max function that you need to compare the lengths of strings which are present in the list.