The main concept that has helped me grasp and use generators is the idea that a generator is an iterable function. I’m going to poke around briefly in the repl to show what methods are available to generators, and how Python uses them.
I’ve ranked my expertise a lot since getting into programming, conversationally, occupationally, and maybe even recreationally once I started to get into the habit. The job postings I see have level requirements: “Senior”, “Advanced”, or “Intermediate”. I hear about “Senior” vs “Junior” devs (and sometimes “Intermediate” here too). I get asked to rank myself, “Beginner”, “Intermediate”, “Advanced.” Or sometimes it’s “1-5”, or in a recent interview, “1-10”. I have opinions about this.
When I first heard about generators, it was in context of Python2, and the difference between range and xrange,
xrange being a generator function. In Python3, I learned, the original
range was removed, and
xrange was renamed
range. If you look up generators in Python, I can almost guarantee this will be the example you’ll see.
I saw an obvious way to clean up my
hacker_rank directory, and jumped into it. I had a series of directories from the Hacker Rank Python exercises in my root directory called
collections_defaultdict, etc. And another series called
I kept forgetting the steps to take, changing the GitHub remote URL and updating virtualenv paths. Here are the steps!
List comprehensions are a quick, easy way to create lists in Python. They offer a short, readable alternative to creating and editing lists using the lambda function and/or for-loops, and they’re considered a more Pythonic way to create and combine the functional methods
map() method is a way to apply the effect of a function on every element in an iterable. It iterates over the iterable, and passes each element in turn into the function you provide it. Each of these return values are appended to a (new) list, which
We started playing around in the repl…
filter() method is a way to filter through an iterable, using a boolean function as a sieve. It constructs a new iterable, filled with the elements from the original iterable that pass the criterion of your boolean function.
In Python, anonymous functions are declared with the
This is a follow up to Python’s Iterables and Iterators
Proficiency: Beginner to Intermediate; I’m going to assume that closures are confusing to you.
Python has iterables and iterators, both of which are invoked during iteration (or while iterating). This is one of those things that is confusing until it isn’t, and there isn’t a great way to narrow that gap.
I kept having this error message come up on ST2, and it seems the solution was to install ST3.
I have learned these useful terminal shortcuts. I use them a lot, so I’ll document them here:
When I first started on Learn.co, I was on Windows, and I used the Nitrous IDE, and they walk you through the set-up. I then used my girlfriend’s iMac, and the set-up was easy, and again they walk you through it.
Note: I was getting this annoying error which seems to happen because I am on Ubuntu 14.04. Apparently upgrading to Sublime Text 3 will fix it. I am now in the process of installing and setting up ST3. I’ll post about that I’m sure.