Today I learned that the reverse of some flag emoji are other flags!

The reverse of some emoji flags.

Reversing emoji

I'm used to getting nerd-sniped by Will McGugan on Twitter, and recently he asked, on Twitter, if we could come up with a string that could not be reversed with the appropriate methods:

>>> "Python"[::-1]
>>> "".join(reversed("Python"))

Here is the original tweet:

Thankfully, for me, I am already used to getting nerd-sniped by Will and I managed to understand where this was going.

I managed to show that reversing doesn't work with coloured emoji, because the colour is kind of defined by having the regular yellow emoji plus the colour. So, when we reverse it, the colour and the hand change sides, and the colouring doesn't get applied:

>>> "".join(reversed("👍👍🏾"))

This may not display properly, so here is a screenshot of this online Python REPL:

Another way to show what is happening is by surrounding a coloured hand with two yellow ones. Notice how the colour moves out of the middle hand:

>>> "".join(reversed("👍👍🏾👍"))

Flag emoji

Another person, replying to Will, figured out that the emoji flags were actually represented by a 2-letter country code. So, when reversing, some flags would start spelling a 2-letter country code from a different country, as shown in the picture at the beginning of this article, and below:

>>> "🇧🇬"[::-1]
>>> "🇬🇪"[::-1]

Quite interesting, right?

Because it may be hard to play with emoji in your REPL, you can also try this online.

That's it for now! Stay tuned and I'll see you around!

I hope you learned something new! If you did, consider following the footsteps of the readers who bought me a slice of pizza 🍕. Your small contribution helps me produce this content for free and without spamming you with annoying ads.

Previous Post Next Post

Blog Comments powered by Disqus.