The code should not be edited. If you make any edits at all to the post, it should just be something to the effect of
For Python 2.7x:
before the code sample, or perhaps add the version relevant tag to the question. If you really want, you could add a comment to the answer linking to another answer that has a 3.x solution.
If you wish to add another answer for Python 3, add another answer for Python 3 (after checking to make sure there isn't already a high quality answer out there for Python 3, of course). I see this very routinely in [xslt]
related questions, where Version 1.0 is still widely used (and sometimes the only option on a given platform), even though 2.0 and 3.0 have been out for some time now. The way it's handled there is to specify which version a given answer is relevant for, and sometimes providing examples for multiple versions if it's not clear what the asker was looking for, e.g.
If you're using version 1.0, this will work:
code sample for 1.0
But if you can use 2.0, here's an easier way to do it:
code sample for 2.0
However, this should only be done by the original author.
You should never assume that viewers will only ever want to see the latest version, and you should never go about "translating" code in accepted answers to something else. It's frustrating to sometimes see that the most highly upvoted and accepted answer isn't relevant on a more modern platform, but that doesn't mean it won't be relevant to anyone and it doesn't mean you should be putting your translation (which may or may not have been correct/trivial) into the hand of the original answerer.