The solution for the shortest-fizz-buzz problem as it stands is not really that short at all even though that is the intended goal of the problem.
I propose the following as a solution. It works in both Python2 and Python3 and is significantly smaller (87 vs 305 characters).
This solution uses various tricks dependent on the way Python interprets code. In particular:
Numbers cannot be ended by letters as per the lexer, so we are able to remove the space between 3 and else.
We can put the bodies of if statements on the same line.
There is no reason to check if something is both divisible by 3 and 5 if we order the checks appropriately and simply concatenate 'Buzz' onto a result string.
We can use whatever number of spaces we would like to delineate scopes.
Python does automatic conversions to boolean values.
The solution for the shortest-fizz-buzz problem as it stands is not really that short at all even though that is the intended goal of the problem.
I propose the following as a solution. It works in both Python2 and Python3 and is significantly smaller (87 vs 305 characters).
This solution uses various tricks dependent on the way Python interprets code. In particular:
3
andelse
.if
statements on the same line.'Buzz'
onto a result string.