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.

5
  • Assuming "which sort is it" means what algorithm, see the duplicate. If your question is something else, please make your question more specific. Commented Jul 4, 2021 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. Commented Jul 4, 2021 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? Commented Jul 4, 2021 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". Commented Jul 4, 2021 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. Commented Jul 5, 2021 at 14:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.