0
Distinguing bewteen 'names' and 'name' on a function (Python)
I have been studying this python guide and it showed this function names = ['jaques', 'Ty', 'Mia', 'pui-wa'] print("longest name is:", max(names, key=lambda name: len(name))) print("names sorted case insensitive:", sorted(names, key=lambda name: name.lower())) Longest name is: jacques Names sorted case insensitive: ['jacques', 'Mia', 'pui-wa', 'Ty'] seems simple but I don't see where "name" is defined, and for python it should be different than "names" right?
3 odpowiedzi
0
It's defined using lambda
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2460/?ref=app
0
so when using lambda it assumes "name" refers to an element of the function?
0
oh ok I noticed that part. I don't see how "name" relates to the elements of "names" tho. I suppose "key" connects them?
thanks, I'm new at this