Katemonkey (In Most Places)

Learning Python, Day 9 — Examples of Lists

So last week, I learned about all the various types of collections there are, and I fully expect the ones that we're getting into now to break my brain just a little. But I have my various film directors, I have Google Colab open, I am ready to go.

08 — Multidimensional List Examples

And right off the bat, I get thrown by the simple 0. Trying to work out why my multidimensional list isn't behaving and finding out it's entirely just because I'm calling the second list 2 instead of 1 because I forgot that 0 starts the count.

Oh well. At least I still get to make fun of Brett Ratner, once I remember that.

directors = [["John Waters",
              "David Lynch",
              "David Cronenberg",
              "Brandon Cronenberg",
              "Ryan Coogler",
              "Guillermo del Toro",
              "Rose Glass",
              "Panos Cosmatos"],
            ["Brett Ratner",
              "Roland Emmerich",
              "Chris Columbus",
              "Paul W.S. Anderson"]]
Melania = directors [1][0]
print(Melania)


>> Brett Ratner

Also, I'm kind of annoyed that he just went "We're going to make these gigantic lists within a list" rather than "We're going to make a bunch of lists, and then call each list within our bigger list to make our life easier."

Because this is so easier to read:

hip_directors = ["John Waters",
                "David Lynch",
                "David Cronenberg",
                "Brandon Cronenberg",
                "Ryan Coogler",
                "Guillermo del Toro",
                "Rose Glass",
                "Panos Cosmatos"]
bad_directors = ["Brett Ratner",
                "Roland Emmerich",
                "Chris Columbus",
                "Paul W.S. Anderson"]
directors = [hip_directors, bad_directors]
Melania = directors [1][0]
Resident_Evil = directors[1][3]
St_Maud = directors[0][6]
print(Melania + ", " + Resident_Evil + ", " + St_Maud)


>> Brett Ratner, Paul W.S. Anderson, Rose Glass

And amuses me.

09 — Tuples

Calling it a "tuple" just makes me think of "tulpa" and then we are in my hipdirectors list because what was Twin Peaks: The Return but nothing but tulpas.

But no, this is about read-only values. Right.

And it's pretty straight-forward, I think. Although he was like "it only use them to temporarily store data", I could, instead, see it as, like, the official canon, the details that are set in stone and that you can't adjust. Like, conversion rates for pounds to kilograms or Fahrenheit to Celsius. That sort of thing. If you're building a weather app, the conversion formulae aren't going to change, so you stick them in the tulpe and then when you want to call the fancy math for converting, you just use, like, convert[0] and it'll pull up the right conversion formula.

10 — Dictionaries Examples

The idea of a key-item and a term-item have been embedded in my brain since the first time I heard of <dl>, <dt>, and <dd>. I love definition lists, and now I have a whole new way to categorise things? Hell yeah.

I'm testing it by making an inventory for Ice Drinks. So I can remember which ones I have. Yes, I am out of Mango Ice. I should get some more.

Ices = {
  "Electric Ice":4
  "Ice Blue":5
  "Mojito Ice":4
  "Mango Ice":0
}
print(Ices["Electric Ice"])
print(Ices["Mango Ice"])


>> 4
>> 0

11 — Ranges Examples

Ranges are for consecutive whole numbers, and have start and end values, as well as steps within.

And, yep, I really need to remember that 0 rule. Again. And that if I want to see each number, I have to convert it to a list.

I don't like how he's saying that if I want to see the even numbers in a list, I have to start at 0 instead of 1 and then step by 2. That's not how that works. There isn't a Star Trek 0.

treks = range(1,7)
good_treks = range(0,7,2)
print(list(good_treks))


>> [0, 2, 4, 6]

Day 9 — Results

That's definitely a good place to end it today, since tomorrow starts with the Conditionals, and boy howdy, are my various lists going to get a workout.

Today's Sticker

An illustration of an orange and white cat, with a chocolate-glazed donut around its neck, floats in a cup of coffee. The coffee cup and saucer say "Have a fresh donut and coffee" as well as "Roasting House" in Japanese Kanji. Underneath all of that is the copyright symbol and "Mofusand", who was the designer.

A Mofusand kitten who is also a donut and also coffee that I got from Tofu Cute.

#kate learns python #programming