A number of years ago I was trying to learn python. Random numbers have always amused me (as I was recently reminded by a twitter nod to the weird usage of spreadsheets).
A user named @context_ing tweeted: “I love finding the ways in which people use spreadsheets. Personally, I use them for mostly budgeting, workout tracking and travel planning. Here’s a few in the wild I’ve found. Would love to see more! Please share if you’ve come across any or have any yourself.”
I felt compelled to reply with my own little story. “Reminds me of a decade old excel project. A playwriting book said something like “I guess it would be a play if you cut up words from a dictionary and pulled them out one-by-one, arranging them into lines of 10 words under character names, but it wouldn’t be a very good one.” So I took the entire public domain text of Oscar Wilde’s classic and had Excel recreate the play on every reopen of the file by randomly selecting words and character names I think using a vlookup and random. The result was interesting (and likely bad theatre).”
The text in question (blasted tweet limits!) was Oscar Wilde’s The Importance of Being Earnest. The resulting play was garbage, but that random interger generation was magical. When combined with other functions it really could do wonderful things for art.
Fast forward some (10?) years and I had a different problem to deal with: I needed to seamlessly transition all staff and clients from one grouping of technology services at one company to a different group of technology services at a new and different non-profit that was going to just continue doing basically the same work for basically the same people.
To remove almost all complexity from this story: I needed passwords; lots of random, unique, and strong passwords.
I once again turned to my friend the random number generator, but this time in python rather than excel. I coded up a script that would allow me to specify the number of words I wanted, unique separator I desired, and―importantly―how many of these unique passwords I wanted to be generated in one go.
I had the program roll digital dice and lookup words from the EFF’s Diceware password list and then spit them out. People would get their passwords and privately think I was just very adept at coming up with wacky sounding passwords, but I did not deserve this misconception as random integers were to blame for everything.
Eventually I thought it would be a good idea to create a sort of Public Service Announcement on the web about the odd truth that a list of words obtained by rolling dice really can be unique.
The end result is a Twitter bot and a Mastodon bot that very frequently tweet out unique passwords they’ve generated (though you probably shouldn’t use them). More people follow on Mastodon than Twitter, and Twitter relatively frequently blocks my bot’s tweets makes me unnecessarily prove that there’s a human behind the bot to get things going again (anyone at Twitter can explain this?).
At any rate, here’s some examples embedded below. Note that I also added the Harry Potter wordlist as well. There are others for your enjoyment on EFF’s site.
Lastly, there are infinitely better versions of this if you’re looking to generate a password. I’d recommend the much more easily installed passphraseme by Micah Lee.
# Import Libraries
import pandas as pd
# Magic Code for Inline Display
# in Jupyter Notebook (if you're using that)
# Create Dataframe from tables at URL for Iowa COVID-19 Testing
url = 'https://covidtracking.com/data/state/iowa/#history'
df = pd.read_html(url)
# There are multiple tables on the page,
# and they are saved in a list.
# Choose the 2nd table and rename to 'df'
df = df
# Set the type for the column 'Date' as a datetime type.
df['Date'] = pd.to_datetime(df['Date'])
# Set the newly typed "Date" column as the index.
df.index = df['Date']
# Create a new dataframe from the original with only
# the 'Pending','Negative', and 'Positive' columns
iowa_testing = df[['Pending','Negative','Positive']]
# Plot this new dataframe as a stacked bar graph
# Invert the axis so time moves forward.
This is the original playscript I wrote for The Art of Python that took place at PyCon U.S. in 2019. I additionally performed the piece at PyCon with the directorial help of Sumana Harihareswara and the stage management work and acting performance as the Figure by Mel Chua.
There were some changes to this script for the live performance. I created slides for the event and they were displayed behind me during the performance and are presented throughout the script below as images.
(slide reads: “THE VOID”)
(the stage is empty. We can make out one person, a figure, front and center.)
(staring, wide-eyed, excited, past the audience – beat * 3)
(slide reads: “This is Kyle –”)
(beat * 3)
(slide reads: “he’s learning the new skill of –”)
(Terrified / heavy breathing / beat * 1)
(slide reads: “computer programming –”)
(Covers his eyes with one hand, twists away from the audience as if what he is about to do might blind him, and clicks a single finger down on an imaginary ENTER key. Bright lights up full. Beat * 3 – he peaks through his fingers.)
It worked? It worked! Ha ha! Yes! Look at that. There it is: “Hello, World!” (Hand on hips – power pose) And you thought this programming thing would be hard.
(slide reads: “but Kyle was in for – “)
(Red lights, loud, blaring sirens)
(Kyle freezes in a macabre, horrific expression and body position)
(slide reads: “– a rude awakening.”)
Not a Programmer
(slide reads: “on not being a programmer”)
No, I’m not a programmer, I’m just better than you are at excel spreadsheets.
(click sound. beat.)
No, I’m not a programmer, I just figured out how to use this query-like syntax with your data in Google’s spreadsheets.
(click sound. beat.)
No, I’m not a programmer. It’s just a little bash script I wrote that helps me journal better from my phone, laptop, and desktop.
(click sound. beat.)
Ha! I wouldn’t say I’m a programmer, I just needed to batch download a really big list of files from a service we were using and python seemed easiest after a google search.
I’m sorry, what?
No, yeah―it did work―ran for about 80 hours straight before finishing. Lots of files.
(click sound. beat.)
Okay―fine―I’m doing some programming: but I’m not really a programmer…
Picking a Language
(slide reads: “on picking a programming language”)
Hi. My name is Kyle and I’ve decided to become a programmer. Several blog posts, books, and twitter surveys have lead me to believe that it is of the utmost importance that I:
(the next sequence is rapid-fire)
(between each beat are quick head, body, and vocal tone adjustments)
(very short beat. matter-of-fact:)
Learn Visual Basic, because my high school teacher gave me a book one time and I can probably find that in my basement if I look hard enough.
(very short beat. sarcastic:)
Learn Bash, because it’s already installed on the self-inflicted torture device known as my Linux Desktop.
(very short beat. in jest:)
Learn emacs lisp, because you’ve already invested the time into memorizing emacs keybindings and you’ve heard it could use a good text editor.
(very short beat. whatever:)
Learn Go because people talk about it on twitter a lot and it was created by Google.
(very short beat. haughty:)
Learn COBOL because it’ll always need maintaining, and it pays the best in my geographic location.
(very short beat. overheard/whisper:)
Learn Python because it’s the “second best language at everything.”
(very short beat. honest:)
(very short beat. snooty:)
Learn R, because it’s the best language at data analysis and graphical representation.
(very short beat. authoritative:)
Learn HTML and CSS because you can make things on the internet―oh, wait―nevermind―there’s disagreement as to whether or not these are programming languages?
(beat. drop all pretense. speak directly to audience―with pure, sincere, exasperation:)
Am I really learning programming if I just know something like “hello, world!” in 10 programming languages!?
… and HTML and CSS?
(slide reads: “submitting a question to stack overflow”)
(Kyle appears frustrated, staring straight ahead and typing in furious bursts.)
Python. Sort. Array. Count. Items. … Search.
No. No. No way! What? No.
(loud sigh. lowered head. stretch neck. he tries again:)
Python. Array. Group-by-count.
(beat. tilts head:)
Oh. No. No, no, no. Not that, kind of…
(beat. types again)
SQL group by with python?
Hey! That’s kind of it…
Oh! Rude! That’s not a helpful or kind response. Do I even want to submit the question here?―mean!―I already don’t know what to ask or how to ask it and apparently that’s a reason to say that you shouldn’t even ask the question.
Maybe I’ll just figure it out myself…>
(a transition. Kyle is holding a rubber duck.)
I’ve heard talking to you helps…
(slide reads: “Kyle works.”)
(duck is gone. cracking knuckles and stretching:)
Done―well, an example anyway, explaining exactly what I want to do and suffers the same problem as my actual work. But I still don’t know how to solve it.
Submit to stack overflow? Submit?
(resolve. clicks enter confidently:)
An answer!―that does basically what I need―and they think I asked a good question―and I got fake internet points!
Okay then. Maybe I can do this.
(slide reads: “on going to a meetup”)
(hands in pockets. kicking dirt. retelling:)
So, I was sick of trying to learn things on my own―by myself, in my basement―and I found a meetup online. It was at a chain soup and sandwich place on a Saturday.
I clicked “attending” and went.
(miming what’s described.)
I got my laptop charged up, threw it in my laptop bag along with a notebook, a pen, and my charger, and slung it over my shoulder and headed in.
I guess I didn’t know what I was expecting? When I walked in and scanned the room looking for more than like four college students with their laptops open over coffee. There they were―I think. Play it cool!
I headed to the counter and ordered a coffee―maybe I’d get thirsty―and walked up: “Is this the python group?”
(uncomfortable smile, holding breath and upright―more uncomfortable long beat…)
It was. That’s what it felt like―forever. They were nice. Young. Old. Macs, Linuxes, and Windows. Qwerty, Colemak, and Dvorak. Gnome and i3. Emacs and Vim and VSCode and Sublime. Working in finance, consulting, healthcare, insurance, startups, and going to college.
They were just people.
I didn’t learn much about programming that day―I did learn that there are real people in real life who care about some of the things I do.
I needed to reach out to more of them.
(break fourth wall. wink.)
Sending an email to a stranger in tech.
(slide reads: “on sending an email to a stranger in tech”)
(straight to audience. single light.)
(like an awkward introduction at a job interview. exasperated:)
Hi. I’m Kyle. I’m new here. I want to get better at this technology thing. Can you help me? You seem like you could help me.
’cause I need a lot of help.
(ding sound. beat. overly formal:)
Hello. My name is Kyle R. Conway. I have a PhD … in Fine Arts … and you do art … and so do I … but you also do tech things … tech things with art. I would like to do what you do. May I join you?
(extends hand for handshake. beat. wide eyes. beat. more intense.)
(ding sound. beat. casual:)
Hey, tech blogger. I really liked your post about unpackaged fonts with permissive licenses. I think that’s really cool.
(ding sound. beat. rapid-fire round. cheeky:)
(ding sound. beat. Irish:)
(ding sound. beat. concerned:)
I promise I’m not a creepy stranger.
(ding sound. beat. intense:)
I. Am. Your. Biggest. Fan.
(gong sound. rubbing eyes. honest:)
This is never going to work.
(quick fade. slide reads: “Kyle’s actual first email to a stranger in tech.”)
Thu, Mar 17, 2011 at 11:36 PM> Máirín, Would the “Nina” font meet the criteria for inclusion? http://www.archive.org/details/NinaPaleyFonts Thanks, KYLE
(slide reads: “Thanks for writing back, Máirín”)
The Figure and the Void.
(A figure stands alone in the darkness.)
(The figure shouts with naive confidence into the void a single word:)
(The figure finishes the phrase―now a question:)
(figure stands awkwardly, concerned, awaitang a response with growing insecurity.)
The below rolls dice in python. I’ve long loved python for dice-rolling―having created a now defunct twitterbot and a mastodon bot―it was nice to write this up briefly as I’m working on re-re-re-learning python.
from random import randint
total_dice = int(input('How many dice? '))
dice_val = int(input("How many sides? "))
rolls = 
high_roll = 0
low_roll = 0
for i in range(total_dice):
roll = randint(1, dice_val)
nums = len(rolls)
for i in range(nums):
print("#" + str(i+1) + ":\t" + str(rolls[i]))
print("Highest: " + str(max(rolls)))
print("Lowest: " + str(min(rolls)))
print("TOTAL: " + str(sum(rolls)))
Output looks like the below:
How many dice? 20
How many sides? 20
Roll # Roll