Today I learned that the reverse of some flag emoji are other flags!
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:
Can anyone give me an example of a string that can not be reversed like this? https://t.co/AwubAJyRRv
β Will McGugan (@willmcgugan) January 20, 2022
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("πππΎπ"))
'ππΎππ'
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!
+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 ππ.