[Tutor] List processing

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Jun 1 23:37:59 CEST 2005

On 1 Jun 2005 cgw501 at york.ac.uk wrote:

> I have a load of files I need to process.

[text cut]

> So basically its a table, separated with tabs. What I need to do is make
> a new file where all the entries in the table are those where the values
> in columns 1 and 5 were present as a pair more than once in the original
> file.

Hi Chris,

Have you thought about sorting?

If you sort them based on specific columns, then elements with the same
columns will cluster together in runs.  So you may not even need Python
much in this case; pipine your input through a 'sort -k1,5' might do the
brunt of the work.

If you want to do this with Python alone, that's doable too in a fairly
straightforward way.  Are you familiar with the "dictionary" data
structure yet?

Best of wishes to you!

More information about the Tutor mailing list