I'm not a python expert, but I think it has the concept of maps (possibly called "dictionaries"). The easiest way to do this is to create a map where the lookup key is the group number and the value is the list of indexes.
In C++, this would be represented as
std::map< int, std::list< std:pair< int, int > > >
std::map< int, std::list< std:pair< int, int > > >
To copy to clipboard, switch view to plain text mode
where the first "int" (the key) is the group number, and the two ints inside the pair are the start and end indexes. So this is basicially a lookup table where the key is the group number and the value is the list of start and end indexes.
You then basically read through the table and do the python equivalent of:
(groupMap[ groupNumber ]).push_back( std::make_pair( startIndex, endIndex ) );
(groupMap[ groupNumber ]).push_back( std::make_pair( startIndex, endIndex ) );
To copy to clipboard, switch view to plain text mode
You don't need to sort the table by group number; the map and its entries will be built in the order in which the rows are processed.
This map is equivalent to a list< int, list< pair< int, int > > >, where the implementation takes care of ensuring that there is only one entry for each unique key.
Be aware that in your proposed implementation as a list of lists, you lose the identification of which pair of indexes belongs to which person. After assembling your list, all you know is the pairs of indexes for the group as a whole.
Bookmarks