+ 1
Could someone pls explain? I dont get it.
words=["I", "love", "SoloLearn"] less =[i for i in words if "o" in i] print(len(min(less, key = lambda x: - len (x)))) Output : 9
6 Antworten
+ 3
your key is lambda x: - len(x)
it will take the opposite of the length, so:
len('love') =4 and len('SoloLearn') =9
but - 9<-4
so the min will be 'SoloLearn' with this key.
+ 2
no, because without a key, python just compare the elements of the list.
but strings comparison is an alphabetical comparison. and it looks like capital letters come before lowercase letters so:
'SoloLearn'<'love' but
'Love'<'SoloLearn'
+ 2
Stefan Reimer
Run this
https://code.sololearn.com/c7S4Mxsbwa9l/?ref=app
The letters WE use each have a number assigned to them which the PROGRAMS use.
'S' has a smaller number than 'l', so min(less) returns Sololearn because of the capital 'S', against 'love' which starts with 'l'.
Hope this helps
+ 1
See if this helps to explain.
https://code.sololearn.com/c4Yh2GM7oLfd/?ref=app
0
Is "sololearn" the output from (min(less)) cause "Love" has a "v"in it?
0
Thx guys that helped alot. I finally got it! Thumbs up!