0

I found the following line of code which I'm unable to google as it has a custom function. Can someone please explain this?

list.sort(key=lambda v: map(int, v.split('.')))

I know this sorts a list but I want to understand which sort is it and how it works.

khelwood
  • 55,782
  • 14
  • 81
  • 108
Sracanis
  • 490
  • 5
  • 25
  • Assuming "which sort is it" means what algorithm, see the duplicate. If your question is something else, please make your question more specific. – khelwood Jul 04 '21 at 12:29
  • @khelwood I've gone through the duplicated question but it only explains the general sort function. however, in this function I want to understand what does lamda means here, what values would pass in v , how ':' operator works in a custom function and does map works normally as we see in other languages? let me know if can reopen it. – Sracanis Jul 04 '21 at 12:35
  • 1
    That would be several different questions. If it wasn't closed as a duplicate, it would be closed as too broad. But see also [What is key=lambda?](https://stackoverflow.com/q/13669252/3890632) – khelwood Jul 04 '21 at 13:07
  • It's for sorting version numbers. Given strings `"2.7.17", "3.9.5","3.10.0"`it will sort them on major, minor, patch as you might expect. It's not robust and will fail on `"3.10.0rc1"`. – BoarGules Jul 04 '21 at 18:54
  • @khelwood thanks for the link you shared and the info about this question. should I delete this question then? BoarGules Thanks man that was quite helpful. – Sracanis Jul 05 '21 at 14:44

0 Answers0