Using an else-statement on loops
One of the less known features of python is the possibility to define an else-statement for a loop. This allows to transform the following code:
to this code:
The number of lines of code that can be saved is not large, but you can save the temporary variable. I think in any case that the code looks nicer =)
Merging dictionaries has been simplified with Python 3.9. The snipped below shows you how dictionary merging was done in Python prior to version 3.9.
In Python 3.9 the same thing can be achieved with the following code
Using separators for large numbers
Since it can be difficult to read large constants without a thousand separator, python allows the bottom bar to be used as a separator. You can find an example below.
I think everyone will agree that the delimiter makes the constants much easier to read.