Negative Stride

Here’s a truly handy thing to learn about Python. First, in addition to slicing lists, it has an ability to stride through them. The default stride is [::1], which simply means walk through everything, but you could choose every other item in a list quite simply: [::2]. But here’s the one that got me: you can stride backwards through a list, so reversing the order of a list is this simple:

backwards = a_list[::-1]

That is so useful.

Iteration

I am genuinely delighted with the Codecademy course on Python: there are a number of basics to programming that I was having a hard time grokking while reading the various books on programming. I don’t think it’s really a matter of book versus interactive website, however. I think it’s just that the folks who wrote the Codecademy course, perhaps in the process of trying to develop something interactive, stumbled upon the sticky points for newbies.

One of those fortunate stumbles was the concept of iteration, which was not something I could figure out on my own. I of course had poured over any number of Python scripts, trying to understand how it was people were able to tell python really nifty things like:

for word in words:
    do this

How did Python know what a word was? Did the script tell it that some place else? Was it part of something the script imported? Was it black magic? It turns out that Python has a built-in sense of iteration that is characters for strings, items in a list, keys in a dictionary. What you call the iterator in a loop is fairly unimportant, Python knows what to look for depending on the type of object with which you are working, the utility of the label you give the iterator is in how easy it is for you to remember when you type it again, and perhaps again, in your description of the actions to be performed (within the loop).

The coders among you are thinking? What. Is. Your. Deal? That. Is. So. Obvious.

Maybe so. Consider me a thick-skulled Cro Magnon. The humbling nature of this experience has been really instructive. I hope to bring it to bear on future students and readers: all the things you should not assume.

Install R with MacPorts

If you are looking to install R using MacPorts, port search R will return 17844 possibilities, only one of which is R itself and three of which are related to R. If you use port help search you will see that there is a better way to search:

port search --exact R
R @3.1.0_1 (math, science)
R is GNU S - an interpreted language for statistical computing

The you need to do nothing more than:

sudo port install R

MacPorts will determine the dependencies:

--->  Computing dependencies for R
--->  Dependencies to be installed: gcc48 icu jpeg pango Xft2 
      gobject-introspection libtool harfbuzz graphite2 pkgconfig 
      readline tiff xorg-libXt xorg-libsm xorg-libice

After that, if you are using Matthew Jockers’ excellent Text Analysis With R for Students of Literature, you should install RStudio. (I don’t find it as useful as iPython’s notebook, but it is a handy all-in-one GUI.)

Mike Rowe Answers

I don’t like most celebrities, and I don’t like the celebrity-oriented moment through which we seem to be passing. I am especially dismayed by how well the celebrity machine works: get famous/known in one domain and the work that celebrity (cum brand) for all it’s worth. And I mean all. It’s insufferable really.

Except … except for Mike Rowe. Why is Mike Rowe my exception? First, because he seems all too aware that luck plays a role in any success — and to be fair to him, hard and unending work plays an equal role (but plenty of people work hard and never catch a break and Mike Rowe gets that, doesn’t seem ever to forget it). Second, because he has take his success and tried to do something honestly good with it. Third, he’s just funnily honest and honestly funny.

Take his response to a young man who was looking for the perfect job: Rowe’s response is get a job and make the most of it, enjoy life and work wherever you are to the best of your abilities. Create opportunities, but don’t wait for them. And quit saying no to opportunities because they aren’t the one you have convinced yourself is the one.

Note to self: take the next job offer that comes your way.