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]
'nohtyP'
>>> "".join(reversed("Python"))
'nohtyP'

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!

Become a better Python 🐍 developer πŸš€

+35 chapters. +400 pages. Hundreds of examples. Over 30,000 readers!

My book β€œPydon'ts” teaches you how to write elegant, expressive, and Pythonic code, to help you become a better developer. >>> Download it here πŸπŸš€.

Previous Post Next Post

Blog Comments powered by Disqus.