May 10, 2010
Unchained melody
Collection concatenation can be done in many ways. A fairly underused way is to use the builtin chain method
Let's suppose you have to concatenate several collections objects, e.g.:
>>> a=range(3)
>>> b=set('ale')
>>> c=(a,b)
One easy way to do that is to create an empty list and use the extend method
>>> cat=[] >>> cat.extend(a) >>> cat.extend(b) >>> cat.extend(c) >>> cat [0, 1, 2, 'a', 'e', 'l', [0, 1, 2], set(['a', 'e', 'l'])]
But another elegant way do achieve the same result is to use the chain function from itertools
>>> from itertools import chain >>> chain(a,b,c) >>> cat=list(chain(a,b,c)) >>> cat [0, 1, 2, 'a', 'e', 'l', [0, 1, 2], set(['a', 'e', 'l'])]
This is especially useful when you have big amount of data because the result of the chain function is an iterator
Document Actions
How to make your team mates think you are someway useful
Disclaimer: vi integralist should skip this post :)
During a technical meeting here in RedTurtle, me and my colleagues were exposing fancy stuffs about software development and I was amazed that the attention of my team mates was triggered by me using a self made Pydev template to insert the encoding on top of Python files.
So here, I am reporting this to the whole planet, hoping someone else will appreciate this simple time saving tip :)
Adding a new template in Pydev is really easy, just go to Window -> Preferences... A configuration window should appear (see image below).

Navigate the tree panel on the left: Pydev -> Editor -> Templates and add click on the New button.
Another window will appear, where you can insert a name for your template (in my case utf8), a description (Insert encoding in the file) and the text to be inserted when this template is used (# -*- coding: utf-8 -*-).
With this template configured, insert che utf-8 encoding in to a file is just as easy as typing ut[CTRL]+[SPACE].