It’s been almost two months since I started studying Python. It took time to find a rhythm with it since there are so many resources to choose from. For example, I tried Linux Academy (which I have access to through work), CodeAcademy, and a few other free options. But none of them resonated with me.
After a lot of trial and error, trying to figure out what works best for me, I’ve been bouncing between the following resources:
The copy()
function lets you make a duplicate copy of a list, while giving it a different reference id
.
To help illustrate this, let’s first create a list of 1s and 0s and set it equal to a variable called binary
:
>>> binary = [1, 1, 0, 1, 1, 0, 1, 0, 0, 1]
This information takes up a specific place in the computer’s memory. This is its id
, which is sort of like its address. The id
of binary is:
>>> id(binary)
140482932383808
If I made a duplicate of this list by setting a variable called binary_copy
equal to…
A tuple is a set of values separated by commas. For example:
'hello', 'goodbye', 'see ya later', 'good morning', 'good night'
A tuple differs from a list in that a list is mutable (i.e. — it can be changed, added to, taken away from, etc.), whereas a tuple is immutable. For example, a list would look like this, surrounded by brackets:
['hello', 'hi', 'nice to see you', 'how are you?', 'good morning']
Let’s set this equal to a variable named greetings
:
>>> greetings = ['hello', 'hi', 'nice to see you', 'how are you?', 'good morning']
A value could be removed…
The other day I ran into a problem asking me to provide one kind of output if an argument was given, and another if no argument was given.
For example — given a book, return the message:
My favorite book is X.
Where X is the given book.
However, if the book is missing, return the string:
I don't like to read.
The exercise came with the following function to manipulate:
def fav_book(book):
pass
I wrongly assumed I could only change text in the function suite (where pass
was), instead of the argument itself. …
While learning to code it’s easy to push through from exercise to exercise, chasing the feeling of accomplishment. I find that everything sinks in more, though, if I take a moment to flesh out my thought process from time to time.
I came across a problem on Hackerrank the other day that required me to find all possible sums of four out of five integers in a list. I’m making a note of what I did here, for future reference.
I used the combinations attribute from the itertools module.
from itertools import combinations
def find_combos(arr):
combos = list(combinations(arr, 4))
print(combos)
…
In my effort to start writing again about my coding journey again, I figured I’d start jotting down small learns, or things I’d like to reinforce in my own words.
Specifically, I recently needed to iterate through both keys and values in a dictionary.
For example, here is my (fake) meal plan for the week:
meal_plan = {
"Monday": "tuna sandwiches",
"Tuesday": "crackers and cheese",
"Wednesday": "caesar salad",
"Thursday": "spaghetti and meatballs",
"Friday": "pizza"
}
Now if I had a simple list, like this:
meals = ["tuna sandwiches", "crackers and cheese", "caesar salad", "spaghetti and meatballs", "pizza"]
I’d be able…
Two-and-a-half years ago I went through a coding bootcamp where we mostly studied JavaScript, Ruby on Rails and HTML. While going through the course, I wrote a lot about what I was learning. I was lucky after the course to get a job as a customer service rep at a Linux based web hosting company. It’s been really good, and learning Linux has been really valuable in a lot of ways. I’ve since wanted to get back into coding, though rather than focus on JS like I was, I decided to dive into Python.
The main reason for this is…
I first heard Rob Bell speak at Wheaton college when I was a student there. The way he spoke was electrifying to me. It opened up worlds of possibility.
He said things I hadn’t given voice to. It was refreshing to hear my thoughts spoken aloud. To realize, I’m not alone.
I’m finding the same thing to be true while reading his latest book, Everything Is Spiritual: Who We Are and What We’re Doing Here. There are so many things he says that resonate with me at a deep level.
Reflecting on his time as a pastor, several years after…
Curiosity is an antidote to despair.
Despair is the spiritual disease of believing that tomorrow will simply be a repeat of today. Nothing new. The future simply an unbroken string of todays, one after another. But curiosity, curiosity disrupts despair, insisting that tomorrow will not be a repeat of today. Curiosity whispers to you, You’re just getting started…I didn’t want to live my life wondering, What if…? I had seen people do that. They had something nudging them in a particular direction, but they didn’t follow it. They didn’t take the risk. They didn’t listen to their heart. And…
Last week I watched The Social Dilemma on Netflix. It was attempting to answer the following questions:
These questions have occupied my headspace for several years. Facebook came out when I was in college, but I only had a flip-phone at the time.
I started to think about this more in 2013 when I got my first iPhone. A powerful piece of machinery that had GarageBand on it, which was exciting to me as a musician. But also — access to the internet, apps and podcasts galore.
…
Coding, creativity, music, and books. Pianist & composer — @vontmer