A Hundred Days of Code, Day 018 - Python Comprehensions, Done!

Continuing my comprehensions journey. Hopefully it makes more sense this time around Notes ** Set Comprehensions ** If I want a set of uniques from a group, I could use a set. Or like Reuven likes to joke, a set is a dictionary with no values; an immoral dictionary 😂 Create it with a somesetcomp = set('somecondition' for a something in somethingbig) or in a simpler manner, somesetcomp = {'somecondition' for something in somethingbig} Protip, better to start with a list comprehension, be done with figuring out stuff and then just switch the brackets at the end....

July 26, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 017 - Python, Advanced Objects, Done!

And we are done with objects! This course finally gave me what I was looking for all these months. The ability to think of and reason about Python, so that I can then think of and reason about, how to build my own programs. Notes Abstract base classes Sounds all high and mighty, but does something pretty logical and simple Helps me test if my object is of a generic (of sorts) type....

July 25, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 016 - Python, Advanced Objects.

Started up with Python Objects today. This seems like a long, hard one. Here’s hoping I learn lots. Knowing Reuven, I know I will. Notes Part 1, Advanced Methods. This section focuses on the dunder methods in Python. By default objects are not equal to other objects even they they are from the same class, with the same attributes and methods. We could implement our own equals method though. The point being, we need to be intentional and methodical, when we design and implement our classses Static methods are plain old functions that I write in my class for use by both the class and the instance....

July 24, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 015 - Python, Advanced Functions, Done!

Delving deeper into Python functions and learning more about them, using Reuven Lerner’s Advanced Python Functions Course Notes The co_* series of attributes inside the __code__ attribute inside most functions gives a wealth of information about a function. For example, looking up the argcount attribute for some function hello, with hello.__code__.co_argcount will give us the number of arguments hello takes. And doing a hello.__code__.co_varnames will give us a tuple of all the local variables in a function hello....

July 24, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 013, Day 14 - Python, Advanced Data Structures, Done!

Notes and experiences for yesterday and today. I ‘wasted’ a lot of time, again, struggling with exercises yesterday and ended up being too zombied to even write the summary post. Have been much smarter about it today. Stopped after about 30 mins and copied and tried to understand the solution. Notes List of Dictionaries Just more convenient than a list of lists, not particularly faster Make it more flexible. Dictionary of dictionaries...

July 22, 2020 · Mario Jason Braganza

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