1
\$\begingroup\$

I wrote a Python 3 answer. I called it Python 3 in the title; however, it works equally well in Python 2. I discovered that I am able to remove several bytes from the answer, but only if I use Python 2 instead of 3. Is it acceptable to change the answer from Python 3 to Python 2, or should I post a new answer?

\$\endgroup\$
3
\$\begingroup\$

Either one is acceptable

I've personally done both of these things it really is up to you. An additional option is to have one answer with both the python 2 and 3 versions in it labelled separately with a bit of explanaiton.

If you want help deciding which to do I would recommend doing a new answer if you feel the the golf is substantially different (a rather subjective metric).

\$\endgroup\$
3
\$\begingroup\$

The choice is up to you

I usually change the version personally. I don't program in Python that often, but for Java 8/10/11 it's similar. I usually use the header Java 8 if it doesn't use any var from Java 10, or .repeat from Java 11. If I do end up using those later on in the golfing process, I simply change the version to 10/11 respectively. I could of course just have a header Java, but I usually use the lowest version required for my function/program.

Although I don't program that often in Python, it's similar. Usually Python 2 is shorter in my experience, due to print ...; in Python 2 vs print(...); in Python 3, or because a mixture of spaces and tabs can be used for code-indentation, for which only one of the two is allowed for Python 3. Python is mainly strong in the added builtin that Python 2 lacks (and Python 3.8 is from what I've seen thus far even shorter in most cases). I don't see any problem in changing the language to/from a different Python version in that case.

If they are substantially different you could also add both versions to your answer, and maybe explain why the code is shorter in one Python version in comparison to the other. Something in the lines of this below for example:


Python 2, 321 123 bytes

code here

-X bytes by switching from Python 3 to 2, allowed me to golf A and B. Initial Python 3 answer can be seen below.

TIO-link here.

Explanation:

# explanation here

Old Python 3 answer:

code here

TIO-link here.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .