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!

Espero que tenhas aprendido algo novo! Se sim, considera seguir as pisadas dos leitores que me pagaram uma fatia de pizza 🍕. O teu pequeno contributo ajuda-me a manter este projeto grátis e livre de anúncios aborrecidos.

Artigo anterior Próximo artigo

Blog Comments powered by Disqus.