-2

I want to sort a list with a function and I want to give this function a parameter which will be used as a key for the sort method.

    def sortBy(self, byKey, reverse):
    self.__playlist.sort(byKey(), reverse)

def sortByName(self, reverse):
    self.sortBy(None, reverse)
IG-_-
  • 9
  • 2
  • 2
    The built-in `sort` function already does this. `self.__playlist.sort(key=byKey, reverse=reverse)`. – Samwise Jun 01 '22 at 16:35
  • when I type that it gives me this warning Unexpected argument(s)Possible callees:list.sort(self: list[SupportsLessThanT], *, key: None = ..., reverse: bool = ...)list.sort(self: list[_T], *, key: (_T) -> SupportsLessThan, reverse: bool = ...) – IG-_- Jun 01 '22 at 17:08
  • Sounds a typo. Double-check that you didn't add any extra arguments in your code, or misspell any of the kwarg names. – Samwise Jun 01 '22 at 17:24

0 Answers0