Posts tagged: PYTHON

99 problems

There is a classic set of programming exercises called “Ninety-Nine Prolog Problems”. Though somewhat tailored to logic programming, they form an interesting set of exercises for other languages. I’ve seen adaptations of varying completeness for Haskell, Lisp, Perl 6, and Python.

I was reminded of this all by a recent blog post by some bloke called Dave who was using the problems as a way to become more familiar with Python. He used Python’s unittest module to test his solutions.

From PHP to Python

A former colleague from my days in print design (and a wonderfully loyal reader of my blog to boot) writes to ask whether he should learn Python. He’s a smart guy with a deep background in typography, publishing, and the Mac. He is not a programmer by trade, but has taught himself enough PHP to build a custom CMS for his newspaper. He writes:

I’ve invested so much time in PHP, and am quite proficient now (not bad for it being more of an avocation), but I respect your opinion and for a long time have wondered about switching.

The Language I Will Kind of Learn in 2008: Smalltalk

In 2007, I took a whack at learning Haskell as my Language of the Year. It was an educational experience on more levels than I had expected. I didn’t get as far with the language as I might have hoped, but I did have the essential mind-opening experience of dealing with a purely functional, “lazy” language. My approach and style in my primary day-to-day language (Python) changed in a positive way. I really like Haskell and hope to continue playing, and possibly working, with it in the future.

Understanding tuples vs. lists in Python

Python has two seemingly similar sequence types, tuples and lists.

The difference between the two that people notice right away, besides literal syntax (parentheses vs. square brackets), is that tuples are immutable and lists are mutable. Unfortunately, because this distinction is strictly enforced by the Python runtime, some other more interesting differences in application tend to get overshadowed.

One common summary of these more interesting, if subtle, differences is that tuples are heterogeneous and lists are homogeneous. In other words: