Python - a clean approach to this problem?

Posted by Seafoid on Stack Overflow See other posts from Stack Overflow or by Seafoid
Published on 2010-06-02T14:47:02Z Indexed on 2010/06/02 15:44 UTC
Read the original article Hit count: 175

Filed under:
|
|
|

Hi,

I am having trouble picking the best data structure for solving a problem.

The problem is as below:

  1. I have a nested list of identity codes where the sublists are of varying length.

    li = [['abc', 'ghi', 'lmn'], ['kop'], ['hgi', 'ghy']]

  2. I have a file with two entries on each line; an identity code and a number.

    abc 2.93
    ghi 3.87
    lmn 5.96

Each sublist represents a cluster. I wish to select the i.d. from each sublist with the highest number associated with it, append that i.d. to a new list and ultimately write it to a new file.

What data structure should the file with numbers be read in as?

Also, how would you iterate over said data structure to return the i.d. with the highest number that matches the i.d. within a sublist?

Thanks, S :-)

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner