I Can’t Believe It’s Not Ruby (Python)

Dario Carlino
4 min readJan 29, 2022

I took the plunge into Python, and this is what I’ve found. Keep in mind these are observations from a newbie Pythonista.

The Syntax is (almost) pseudocode

Doesn’t get better than this, the syntax is sweet and intuitive, and here I was thinking that Ruby was the pinnacle of user-friendliness

While Ruby methods (aka functions) are defined like this:

Ruby Method

on Python we can omit the ‘end’ to close the block:

Python Function

Python really does depend on tabulation and it took my monkey brain a minute to pay attention to that.

When it comes to string interpolation there are a couple of options in both Ruby and Python.

My first Python CLI app: Super Bowl Boxes Generator

It’s pretty simple really, and the first useful thing I’ve done in Python (I don’t really know much about football)

Super Bowl Boxes Generator

The objective is to generate a 10X10 grid of paired numbers that go from 0 to 9, representing the possible score per game quarter.

Breaking it down

The random module is imported to allow me to randomize the order of the numbers, after that I declared the function mixer, that takes no arguments.

This line…

afc = nfc = [*range(0, 10, 1)]

is a fancy way of saying this…

afc = [0,1,2,3,4,5,6,7,8,9]
nfc = [0,1,2,3,4,5,6,7,8,9]

instead of declaring the both lists (arrays in ruby) with all the values, I’ve used range to generate them, it’s more verbose but it’s a good way for me to practice the new concepts.

After the lists are formed and declared, we shuffle them; shuffle being part of random, it does as it says and it shuffles the values in place (it’s destructive as it modifies the original list.)

Shuffle!

I generate the list of lists that will become the grid to be displayed…

Super Bowl grid, or sup_grid

and here I iterate through one of the lists with enumerate. I could have done it with a regular for loop, but that wouldn’t have given me an index number, and yes I could have created it myself but this is more DRY.

Grid Creation

The first loop loops through the afc list, and for every iteration of that, I loop through nfc, appending a pair of values (ie: ‘3–6’) to each list inside the sup_grid list, effectively forming the 10x10 grid of random values. The reason why it had to be done in that specific way is because the NFC values have to be the same vertically and the afc values have to be the same horizontally. It’s little confusing but you’ll see it in the end result.

Finally the result is printed-outputted to the terminal

Let’s print

that last for loop could have been simplified like this:

Simplified results

but to make the output more legible all the other print() statements were added.

The last line just calls the function

The Result

It works like a charm, every time.

The displayed list of lists

--

--