Python Algorithm Pt.1: Array

Che Kai LIANG
3 min readOct 3, 2021

Hello to my 3 viewers! I am officially back in Medium to write MORE outrageous puns and MORE Python tutorials! So what in the HTML are we waiting for? Today, we will be introducing: Algorithm! One of the most essential knowledge and also one of the most hardest to spell words, so let’s just call it ALG for the rest of this story, because I am NOT spelling that again. Now, where were we? Ah! Introducing ALG. I was bored so decided to revise ALG. And it makes a good medium story, so here I am. Oh, by the way, Al Gore was tapping his foot impatiently while waiting for the elevator to arrive. The guy next to him said “Nice Algorithm!” Al Gore responded: Al Gore take the stairs. HAHA…you get it? Because AI-Gore-rhythm? HAHA! Lets get started.

First step: I will explain what an array is. You can pretend that there are 5 derps in the room. The first derp is called Derpen. The second is called Derpohn. The third is called Derpary. The fourth is called Derp-kai. And the final is called Derpavid. Now, the five derps are sitting in this order: Derpen, Derpohn, Derpary, Derp-kai, and Derpavid. One thing to note is that an array ALWAYS starts with 0. So: if Derpen is sitting the furthest to the left, aka the first seat, his number in the array is 0. So the first seat is 0. The second seat is 1. The third seat is 2. And so on. So, our array would look like this: x=array(‘i’, [Derpen, Derpohn, Derpary, Derp-kai, Derpavid]). We are defining “x” to be the array the five derps are sitting like right now. So if we print x, our array would appear. If x is defined as our array, if we want to change one of the names/numbers in our array, we can do this: x[2] = Derpappalapap. The subject x(defined as the array listed above)’s second seat in the array equals Derpappalapap now, because Derpohn left and Derpappalapap sat in his stead. Now x[2] equals Derpappalapap. Easy, right? But we are not done yet.

Now to the “append” insert: Using the append function you can add to the array. Now, Derpohn is back, but the 2nd seat is already taken. He pulls up a sixth chair and sits on it. Now, we have to do the following: x(our defined array).append(the new function). It will look like this: x.append (Derpohn) now, the array would be: Derpen, Derappalapap, Derpary, Derp-kai, Derpavid, then Derpohn. Now, we appended Derpjohn into the array. A more specific way to do this is that if Derpohn REALLY wants to be at seat 3 for what ever reason. To do this, simply x.insert(3, Derpohn).

Here is an example of an array:

from array import *x=array('i', [5, 15, 25, 35, 45])print(x)x[2] = 100print(x)for data in x:print(data)i = x.index(35)print(x.index(35))print(i)print("====================")print(x)x.append(100)print(x)print("====================")for data in x:print(data)print("Hello there!")x.insert(3, 1000)print(x)

Results:

Today, we delved into the BORING depths of Algorithm. Gee, that was a mouthful. I cant even write puns now. Uh. Welp, until next time, in part 2!…I am going to take a break.

--

--