Things you can do with Python

Here is a Python assignment from a journalism class at Stanford:

Build face-grep in Python

Go ahead, look at it. Don’t get scared. Just look at it and try to understand the concepts.

You could actually DO this assignment. You could.


Everyone is bad at this when they get started. Everyone.

I sent a link to this article via email last week or two weeks ago, but I thought I should link it here too, in case you did not read it yet.

Getting a job in journalism code: Two recent grads want to calm your job search fears

It’s such an outstanding article because it’s not all about how the two authors — a young woman who now works at ProPublica and a young man who now works at The New York Times — loved data and code and produced great interactives from the start. NOT.

Instead, it’s about how bad their early work was. How they (and others) look back at their early efforts now and think, wow, that was so poor! They have linked examples. You can look for yourself. And I think you will agree. Really? You got a job with that?

But not long ago, these two successful journo-coders were just like you.

Q: Am I a real programmer? I spend most of my time Googling error messages.
A: Yes. That’s what most of us do.

And I was the same way, once upon a time:

Q: Whenever I see someone write code, it’s like they’ve got everything memorized. Do I have to memorize everything?
A: You do not need to memorize everything. Programmers know what to write next (like exact phrasing of CSS or JavaScript functions) because of repetition, familiarity, and having looked it up time and time again.

You are good enough to do this. You ARE.

Q: I feel like there’s way too much to learn and no way I could learn it all. What do I do?
A: Here’s a secret, everyone feels this way.

There’s lots of advice in the article, so I’ll share just one more and then leave you to read it for yourself:

Q: Do I need to have a website?
A: Holy moly yes. It doesn’t have to be fancy, but it needs to exist. Heck, Sisi’s website redirects to an site. But the website’s secret goal is to funnel people to your portfolio, which should also be online. … your portfolio is going to be your best champion in getting hired. It’s much more important than your resume (though don’t skimp there, do things like list your skills) …

Be inspired.

How we use algorithms

Many students had difficulty figuring out how to code the number guessing game in class on Monday, Feb. 24.

You already know ALL of the building blocks of programming. This is (pretty much) everything:

  • variables
  • functions
  • if statements
  • loops (for and while)

So here is something else to think about:


An algorithm is like a recipe: a step-by-step process for performing some activity. You may look at an algorithm as the steps your program goes through to solve a problem. For example:

High Score Algorithm

  1. Game is over
  2. Compare player’s score to high score
  3. If player’s score is greater than the high score then the high score variable is reassigned the player’s score
  4. Display new high score

There are algorithms that exist for many common programming problems such as sorts and indexes. (source)

This is the problem-solving method you will need to develop. When I told you “break it down,” this shows one example of breaking down a problem that needs to be solved. What do I want to do? I want to tell the player if she has the high score. How do I find out of she has the high score? And so on.

You must first reason through the TASKS you want to do. THEN think about the code you will need to write to make it happen.


Imagine a dice-throwing game: Any player who gets doubles will win.

  1. Player throws two dice.
  2. Computer throws two dice.
  3. Did both get doubles? (What happens?)
  4. Did only one get doubles? (What happens?)
  5. Did no one get doubles? (What happens?)

Now, the algorithm:

  1. Throw two dice for the player. Save two numbers, possible 1 through 6 for each.
  2. Throw two dice for the computer. Save two numbers, possible1 through 6 for each.
  3. Compare two faces of the player’s dice to check for doubles.
  4. Compare two faces of the computer’s dice to check for doubles.
  5. If no one has doubles, announce or print that.
  6. If both have doubles, announce that it is a tie.
  7. If the human has doubles, announce that the human wins.
  8. If the computer has doubles, announce that the computer wins.

The order of 5 through 8 might change, depending on how you want to write your if-statement.

Here is another example (a very simple one).

You can do this in either Python OR JavaScript! Give it a try!

Double major in journalism and computer science

This quote —

… the fields of mathematics, statistics and computer science are ever more important to the emerging fields of data journalism, information graphics, and news applications. That’s where the jobs are. That’s where the industry is heading (arguably, already it’s already there). That’s the new quality and standard to which we need to hold journalism.

We’re never going to fill these jobs or really make impact in this space and push forward if we don’t properly teach and prepare the young’uns coming up. Myself included.

— comes from an article written by a journalism student. You should read it:

Re-thinking J-school, by Katie Zhu.

Do you feel like writing code is still hard for you?

In this very amusing blog post (you must read it to the end!), by student Michelle Bu, you’ll find out how hard her first coding experience was for her:

21 Nested Callbacks

I was laughing out loud as I read it.

I’ve realized that with each piece of code I’ve written since my triangles, I’ve only gotten better at “Googling it,” debugging, and being generally competent about miscellaneous programming topics–and it’s all because I saw each and every silly project through. — Michelle Bu

So 21 months ago, she didn’t even know how to write a loop. Now she’s a Ph.D. student in computer science.

Here is her first attempt (21 months ago), and here is her new, responsive, fabulous version.

Check out Michelle’s Projects.

What kind of salary will you earn?

I recommend two online articles for you this week:

Median salary for reporters $35K, $52K for editors (Poynter, Feb. 1, 2013)

Four steps to learn the web through coding (Knight Foundation blog, Feb. 1, 2013)

Both articles are quite short. The first one has several very informative charts that show current salaries for U.S. reporters, TV producers, etc. I particularly liked the chart titled “Employment and establishments in Internet publishing, 2001–2011.”

In the second article, some things will be familiar to you already — but I think you will gain something if you read the article and look for tips you don’t already know. I’m sure you will find some.

If you wonder how I find posts like this, it’s all thanks to Twitter. I made a list of journalism industry sources. I get a lot of good stuff from the tweets from that list. Learn more: How to Use Twitter Lists.