James Tauber's Blog 2006/04/15


blog > 2006 > 04 >


Python Tuples are Not Just Constant Lists

Greg Wilson is suggesting things Python 3000 could leave out and suggests tuples.

In the comments, Phillip Eby holds him to task for the assumption that tuples are just constant lists:

Tuples are not constant lists -- this is a common misconception. Lists are intended to be homogeneous sequences, while tuples are hetereogeneous data structures.

I think it was years into my use of Python that I realised this and stopped thinking about them as just constant lists. It was a powerful revelation for me.

So while I agree with Greg that many (most?) programmers don't understand the distinction, I think they are missing out and that we'd be better off improving the way lists and tuples are documented than try to conflate what is, in my opinion, a very useful distinction.

One way I'd express it (in addition to Phillip's quote above) is that the index in a tuple has an implied semantic. The point of a tuple is that the i-th slot means something specific. In other words, it's a index-based (rather than name based) datastructure.

This notion of 'tuple' is very important in relational algebra (as Phillip also points out) and so I've been thinking about it in the context of relational python too.

When I started playing around with relational python (which I need to get back to blogging about), it occurred to me that it might be useful to have the notion of a tuple whose slots could additionally be named and then accessed via name. I implemented it that way in Basic Class for Relations.

UPDATE (2011-11-22): of course, the idea mentioned in that last paragraph is now a reality in the form of Python's namedtuple.

by : Created on April 15, 2006 : Last modified Nov. 22, 2011 : (permalink)


Fire Someone Today

Even if you're not interested their products, Logos Bible Software is a fascinating company on a number of levels. From the look behind the scenes you get from their blog to their innovative community pricing model where the market votes on the product priorities and pricing before production even starts, Logos is an interesting company to watch and learn from.

So I was delighted last August to discover that founder and CEO, Bob Pritchett, was writing a book on practical advice for startups called Fire Someone Today. Bob kindly sent me a PDF draft and I loved it—entertaining but also honest and very insightful.

Well, the book is now available from Amazon and, in typical Bob Pritchett style, Logos is offering $20 credit on their online store for anyone who buys the book from Amazon by midnight tomorrow. A nice deal given the book costs less than $10.

Even if you have no interest whatsoever in Bible software, it's a book worth taking a look at if you're interested in startups and entrepreneurship.

by : Created on April 15, 2006 : Last modified April 15, 2006 : (permalink)