Back to Lesson

Custom Sort Logic

Use sorted() with a functional key to manipulate lists intelligently.

Instructions

  • You have a list of strings representing file sizes:
    files = ["10MB", "2MB", "150MB", "45MB"]
  • Create a function
    strip_mb(s)
    that returns
    int(s.replace("MB", ""))
    .
  • Use
    sorted()
    on the list with
    key=strip_mb
    , and print the resulting list.
main.py
main.py