Processing a list of lists

dequalsrxt's icon

Say I have a master list made up of sub-lists that looks like this:

A 23 78

B 49 12

C 23 92

D 56 87

E 23 96

etc.

and I want to thin out repetitions in the second element of each list, so I get something like this:

A 23 78

B 49 12

D 56 87

How do I go about this? A further complication - how might I thin out repetitions in the second element based on the third element? For example, of the sub-lists with repeating second elements, I want to keep the one with the highest number in the third element, resulting in this:

B 49 12

D 56 87

E 23 96

The context is I'm playing around with a FluCoMa patch that slices a buffer, each slice gets assigned an identifier (an integer) and then mapped to x/y coordinates (floats). I'd like to round the coordinates, then filter out slices which have repeating x or y coordinates. Maybe based on slice length, so keep the longest/shortest? Or maybe based on nearby coordinates? I'm not sure yet, I have to figure out the processing part first.

Roman Thilenius's icon

the most simple way to compare all elements in a set against all other elements is brute force: have two counters running, one for A (1-8) and one for B (1-8, 1-8, 1-8, 1-8, 1-8, 1-8, 1-8, 1-8). (or optimize it a bit by excluding double combinations)

the actual process in the concrete case could look like this:
[route C]
zl slice 1]
[==]
when 1, then delete the C entry

double_UG's icon

Max Patch
Copy patch and select New From Clipboard in Max.

..............................................

Source Audio's icon

coll can do both for you

dequalsrxt's icon

Ah ok, I've been playing with coll, but I don't know it very well. I didn't know about the sort message, very handy. I get the general idea behind Roman's route strategy, but I haven't quite figured out how to patch it yet. I think I'll keep playing with coll since all the info mainly comes from dictionaries.

Roman Thilenius's icon

my suggestion is meant as a general solution for "everything" which can be done with or to coll contents - of course, where they exist, the built-in functions of coll can be much easier to use.

dequalsrxt's icon

I started to use part of your solution, insofar as I understand it, but I swapped route for coll and the counters for an uzi, then unpack the coll ouputs, compare them with == and... that's about as far as I got. It's a mess, haha. Which I guess is probably inevitable whatever the solution is. Oh well, as long as it works.