This is a spoonerism: butterfly
→ flutterby
.
See the link at the end of this post.
I had hoped to use list slicing and tuple assignment to transpose the 'b'
with the 'fl'
, using the code below. Then 'butterfly'
would become 'flutterby'
. The following was written in hopes that the contents of the list would be buffered as the exchange was in progress, enabling a clean exchange of slices:
spoonerism = 'butterfly'
spoonerism = list(spoonerism)
spoonerism[0:1], spoonerism[6:8] = spoonerism[6:8], spoonerism[0:1]
spoonerism = ''.join(spoonerism)
print(spoonerism)
Disappointingly, the output was:
fluttebly
It’s just not as poetic as flutterby
. …
So, then I decided to verify what would have happened if, instead of the buffering that I had hoped for, the two slice assignments had been performed in succession, as follows,
spoonerism = 'butterfly'
spoonerism = list(spoonerism)
spoonerism[0:1] = spoonerism[6:8]
print(''.join(spoonerism)) # intermediate result
spoonerism[6:8] = spoonerism[0:1]
spoonerism = ''.join(spoonerism)
print(spoonerism) # final result
Output:
flutterfly
fluttefly
The output makes sense, though it is, of course, not what was originally desired. However, it also differs from the original disappointing output, proving, quite bluntly, that the original attempted tuple-powered slice assignment was not simply decomposed into two successive slice assignments.
The following produces the desired result, but why?:
spoonerism = 'butterfly'
spoonerism = list(spoonerism)
spoonerism[0:1], spoonerism[7:9] = spoonerism[6:8], spoonerism[0:1] # works, but huh?
spoonerism = ''.join(spoonerism)
print(spoonerism)
Output:
flutterby
Let’s decompose the previous into two successive slice assignments for comparison:
spoonerism = 'butterfly'
spoonerism = list(spoonerism)
spoonerism[0:1] = spoonerism[6:8]
spoonerism[7:9] = spoonerism[0:1]
spoonerism = ''.join(spoonerism)
print(spoonerism)
Output:
flutterfy
Hmmm … not the same result as from the previous hack, but now that is no longer surprising.
OK, I’ve weathered the initial disappointment, but just what is going on when this is executed as in the original attempt?:
spoonerism[0:1], spoonerism[6:8] = spoonerism[6:8], spoonerism[0:1]
Just for interest:
The above was EDITED on November 20, 2021 to add a little commentary.