Seven Tips To Clean Code With Python

Here are the seven tips and code bites that I use every day in my work as a data scientist.

Louis de Bruijn
Analytics Vidhya

--

code bites
Image by author

In this story, I will share what I use in my day-to-day work and what has helped me improve my code. Check the list below to see if there’s anything new for you!

  • String formatting with f-strings
  • Platform independent directory delimiters
  • Variable unpacking and the _ operator
  • .get instead of [key] for dictionary iterations
  • Loop two iterators with the zip function
  • The power of list comprehensions
  • Multiple assignment with * and **

String formatting with f-strings

Hallelujah! That is what I thought when I learned about the Python 3.6+ update that includes a new way of formatting strings: the Python formatted string literal. String formatting in Python has come a long way.

--

--