Archives for the Month of February, 2008

Learning Python: Chapter 9

Tuples are immutable sequences.
Tuples with just one element require a comma after the element the be distinguishable from an expression.
No methods can be called on tuples.
Comparisons and truth tests traverse data structures.

>>> items = [ [random.randint(0, 2) for m in range(3)] for n in range(10) ]
>>> items
[[1, 2, 0], [1, 0, 1], [2, 0, 2], [...]

Learning Python: Chapter 8

Lists can be nested without explicitly using list references.
As with strings, since both are sequences: list concatenation is done with +, repetition with *
Straight forward membership tests for lists: if element in list
The bultin function range returns as list of numbers, whereas xrange returns an object that generates numbers on demand, therefore being very efficient [...]

Learning Python: Chapter 7

Strings are immutable sequences of characters.
Single- and Double-Quoted Strings Are the Same, they both don’t interpolate at all.
Adjacent string literals are concatenated automatically.
A backslash in a string literal that is not part of an escape sequence is kept in the resulting string.
Unicode string literals are prefixed by the character u; \u und \U can be [...]

Template Toolkit - Now With Added Python Goodness!

I had some idiosyncratic learning experiences lately. I read something about two things I want to learn about and suddenly, without explicitly searching for it, stumble upon something that deals with both of them. This happened again this morning. The two things that I was already learning were Python and the Template Toolkit.
As a Python [...]

Learning Python: Chapter 6

L1 = [1, 2, 3]
L2 = L1
L1 == L2 and L1 is L2 both yield True. 
L1 = [1, 2, 3]
L2 = [1, 2, 3]
L1 == L2 yields True (same values), but L1 is L2 yields False (different objects).
[...]

Learning Python: Chapter 5

After four chapters of introductory details I finally arrived at the in-depth explanation of Python that I actually looked forward to. Here’s all I found noteworthy from a Perl programmer’s point of view.

There are functions for explicit type conversion between individual numeric types: int(3.1415), float(3), long(4).

After saying
[...]

Debug::Phases

Debug: hases - Announce BEGIN and INIT phases to help locate problems:
This tiny module does nothing but announce the start of the BEGIN and INIT phases, recording how long the compilation (BEGIN phase) took. It’s handy for tracking down whether particular problems are compile-time or run-time, and also for evaluating the time-cost for using [...]

Losing techniques

Euclidean distance - Wikipedia:
The technique has been rediscovered numerous times throughout history, as it is a logical extension of the Pythagorean theorem.

Rediscovered? How does a technique get lost in the first place?

The foolproof way to eliminate fall-out

In the wikipedia article about information retrieval it says:
It is trivial to achieve fall-out of 0% by returning zero documents in response to any query.

If you are not into information retrieval and don’t want to read about it, here’s what the above says in layman’s terms: It is trivial to say nothing wrong by not [...]

Conway’s Game of Life

While reading something about artificial neural networks I just thought about Conway’s Game of Life. I remembered that when I first read about this, I wanted to try it out and so whipped it up in Javascript. And guess what? My minimalistic approach to Life in HTML and Javascript was still on my webserver.
Click the [...]