3 Mar 2005 titus   » (Journeyer)

Generating all L-tuples from a given alphabet

I had a muuuuuch longer diary entry written, but then I realized it was all shite and needed rewriting. Meanwhile, here's something that I thought was cute:

alphabet = ('A', 'C', 'G', 'T')

def rN(L, *args): """ Generate all L-tuples from the given alphabet. """ if L == 0: print args return

for letter in alphabet: rN(L-1, letter, *args)

For example, rN(2) gives this:

('A', 'A')
('C', 'A')
('G', 'A')
('T', 'A')
('A', 'C')
('C', 'C')
('G', 'C')
('T', 'C')
('A', 'G')
('C', 'G')
('G', 'G')
('T', 'G')
('A', 'T')
('C', 'T')
('G', 'T')
('T', 'T')

There are just *all sorts* of tricks you can do with Python's function passing semantics, ehh?

Rant of the Day

Why must people post sub-200k binaries via SourceForge's incredibly crufty load-balancing download system?!? It makes them difficult to download, IMO...

--titus

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!