You might have noticed this part of the 2016 Emoji Report – part of the graphic features an emoji for each of our subscribers. It’s a randomized ordering of all the different skin tones of the 👩💻 and 👨💻 emoji, repeated [number of subscribers] / 12. Our subscriber count wasn’t exactly divisible by 12, so I deleted a few blond 👨💻 because usually they are over-represented.
A note on inclusion: I nearly used the 🗣 emoji, but I decided that was too anonymous, and anonymous defaults are usually male. We think that at least half our subscribers are women, so this seemed like a nice way to show that off. I also debated whether to use the default yellow emoji, but opted to in part because of my colleague John’s article Did I Grow Up And Become The Yellow Hand?
We needed so many emoji, that I knew I would have to script it. I tend to script things in Python, and figured I could use iPython and that would be cool. In the end I ran into a couple of things and opted to make a file instead. Those things were: emoji support in the terminal was terrible (come on Apple!) and I couldn’t see what I was doing (emoji support in XCode is great), and writing to a file from iPython seemed a bit annoying (of course I go to look that up, and find that it’s actually straightforward – is there a word for the StackOverflow answers you find after you’ve already solved your problem?).
The only other gotcha was that I needed the elements in a list to shuffle and random them, which makes sense. Here’s the entire four lines of code! Notice that at the top the encoding is specified.
# -*- coding: UTF-8 -*- import numpy import random # A list of the emoji we want to randomize. emojilist = '👩💻','👩🏻💻','👩🏽💻','👩🏼💻','👩🏾💻','👩🏿💻','👨💻','👨🏻💻','👨🏼💻','👨🏽💻','👨🏾💻','👨🏿💻' # Repeat it X number of times (I'm using 10 here as an example). repeated = numpy.repeat(emojilist, 10) # Randomize the list (in place). random.shuffle(repeated) # Join the elements together with nothing in between, and print it out. # It's easy to pipe the output to a file using ">". print ''.join(repeated)
One reply on “Creating a Randomized Emoji String in Python”
[…] found a simple Python 2 script to randomize (and repeat) a given sequence of emojis; however, none of the usual programs I use to write, test, or edit Python scripts were able to […]