A Hundred Days of Code, Day 012 - Python, Advanced Data Structures continued

Ok! Had a nice refreshing break, yesterday being Sunday. Back to work today! If today’s notes, feel a little light, that’s because I was struggling with exercises. Notes Part 2 A lightweight solution to classes, if I am just combining all sorts of data structures is the built-in collections. Some of them could be List of Lists List of Tuples List of Dictionaries Dictionary of Dictionaries Dictionary of Lists Mostly use them to solve tricky issues....

July 20, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 011 - Python, Advanced Data Structures

Started with a new Reuven Lerner Course, on Advanced Data Structures.. Aiming to comfortably finish this in a week. Notes and experiences, follow. The course is three parts. Part 1 - Deep dive into the common data structures Part 2 - Combining Data Structures. Lists of lists, Dicts of lists, Tuples of Lists and so forth. How far can I go without classes? Or how can I enhance my classes with this approach?...

July 18, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 010 - Python Functions, Basics Done!

Today was hard! Notes ‘*args’ way to get multiple arguments without having to assign placeholders for them it scoops up all the arguments and gives it to the function in a tuple. I could then loop over it with for. I just put * in front of one of my placholders et voilà, def example_func(*catch_everything) I can define placeholders to catch specific arguments, but those need to be before my ‘*args’....

July 17, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 009 - Python Functions, Basics

Started up with learning about Python function basics, today. Notes follow. Using the Lerner pool of wisdom, as usual. Why do we need functions? DRY (Don’t Repeat Yourself), because we can take stuff that is repeatable, assign it a nickname and just call that nickname over and over, instead of tediously writing all that stuff over and over and over If want to modify something, I can just call it (by the nickname) and then add my little spice to it....

July 16, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 008 - Python Basics, Lists, Tuples, Dictionaries, Sets and Done!

This was an amazing run! Learnt lots. Done with the basics course. Woohoo! Notes With lists Not pythonic to mix types can iterate, slice and dice, search, get lengths, transmute them (for e.g. reverse items in them) just like strings can have lists of lists! lists are mutable, unlike strings. can change items/elements of a list If i create a list from another list, the new list items reference the old list items if i want to copy elements from a list rather than reference them, I’ll go newlist = oldlist[:] which will copy the elements from the old list into the new one, rather than create references to the old ones Realise that there is a difference between changing the values of a variable and between changing elements of a list....

July 15, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 007 - Python Basics, Variables, Basic Data Types, Strings and Loops

Started with the Reuven Lerner, Intro Python:Fundamentals course today. Made surprising headway, even though today was crazily demanding with work and personal stuff. Notes The difference between == and is If you want to see if two things are equal, use == like, is 2+2 == 4 If you want to know if two objects are the same thing. if they are just pointers to the same memory location, use is....

July 14, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 006 - Starting and Quitting Comprehensions

I know I said, I’d start with the basics, Reuven, but please forgive me this once :) Will do the rest, bottom up :) Have started up with this, because I’m fascinated with how folks manage to build in so much functionality into short, easy to read statements. To my mind, comprehensions are the pithy proverbs of the programming world. So here goes … Notes This style of writing code, comes from functional programming Functional Programming is another style of writing code It assumes that data is immutable....

July 13, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 005 - Magic Methods and Winding Up OOP

Done with Reuven Lerner’s OOP basics Notes len does the right thing across multiple types of objects. it counts characters in a string, elements in a list, and key-value pairs in a dictionary. how does it know how to do that? that is because len uses a magic method (methods that have a __ for a prefix and suffix) len uses the __len__ method which i can use in my own classes, to implement a len method for my classes If I choose to do so, I need to realise what those underlying methods expect to return and return the same type in my classes....

July 12, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 004 - Class Attributes and Inheritance

Learnt about Class Attributes and Inheritance, today. Notes The way we write functions/methods and define classes might look similar, class CrazyTalk(object): and def how_now_brown_cow(): The way they behave/execute, though is wildly different. Classes run / spring to life as soon as the program launches. Functions don’t, unless they are called. Realised that objects are containers. What you can do with the object depends on what is in it. Does it hold a dictionary with various methods to modify it?...

July 11, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 003 - Methods

Learnt about methods today. Notes follow … My understanding about methods? They are functions in classes that help me manipulate the data the objects contain when they are created. I have been using something them subconsciously all along. The __init__ method, that is called/run automatically every time an object is created. Aha A nice way to unpack the .notation i use Let’s say I have a class SquareNumbers that has a function (method) ­— x2 — that will, you know, square a number....

July 10, 2020 · Mario Jason Braganza