menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Stop writi...
source image

Medium

1d

read

135

img
dot

Image Credit: Medium

Stop writing okay Python functions. Start writing good ones

  • To split items bought according to quantities, a function named 'split_items_and_quantities' will be created.
  • Type hinting is used to specify expected data types for variables, function arguments, and return values.
  • Documentation strings provide information relevant for using the function, including definition, arguments, and expected output.
  • The function rejects incorrect input types before execution and includes error handling.
  • Following the Single Responsibility principle, the function focuses on separating items from quantities using regex and appending to columns.
  • Efficient code includes error handling using try-catch blocks to highlight and capture runtime errors.
  • The function combines multiple tasks within its logic, including parsing items from quantities and creating a data frame.

Read Full Article

like

8 Likes

For uninterrupted reading, download the app