Python Forum
How to Sorted and display the Subclasses of BaseException
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Sorted and display the Subclasses of BaseException
#10
(Feb-10-2021, 11:26 AM)Fernando_7obink Wrote: about the 'str' in key ... how does it work ? does it mean the key = str will take each element and change them to str type data and compare them ?
yes, I think it's pretty clear from the docs I quoted in my answer. It will apply function supplied as key on each element in the list and use the result to compare/order the element, in this case the function is str() - a built-in function, in the @Gribouillis example - a lambda function (that is anonymous function) which takes one argument klass (i.e. one element) and returns klass.__name__ attribute (which is also a string).
Fernando_7obink likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: How to Sorted and display the Subclasses of BaseException - by buran - Feb-10-2021, 12:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A function that checks if the list is sorted pooyan89 16 16,948 Apr-22-2024, 09:14 AM
Last Post: DeaD_EyE
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,071 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  defining a function to see if a list is sorted Siylo 14 7,080 Nov-29-2018, 05:25 PM
Last Post: wavic
  sorted list not displaying Crackity 6 5,124 Jul-18-2017, 12:50 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020