4.1. Exercises

Flake8 and Black

Formatting your Code

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Let’s take the function named cleanup() which drops duplicate rows and columns. Rewrite the function code (not the docstring) so that it’s written with necessary spaces and indentations.

Tasks:

  • Amend the function cleanup() so that it adopts an approach that has spaces where necessary and blank space is removed. Make sure that you have indentations and empty lines where necessary.
Hint 1
  • Are you adding spaces between operators?
  • Are you removing spaces where appropriate?
  • Did you fix the indentation error?
  • How about removing the blank lines before the return statement?
Fully worked solution: