Finding the index of an item in a list

Aug 19, 2013 at 8:23pm

Finding the index of an item in a list

Hello! I’m a new member of the forums, but it looks like there’s a fantastic community here that I’m excited to be a part of. Anyway, my question:

If I have a list, say 2 3 0 4 0 5 6 0 7 0 1 0 what’s an efficient way to get the index of the “1?” I’ve tried looking at the documentation of the zl object, but I can’t find anything that fits what I’m looking for.

I’m coming from a traditional programming background, but can’t use JavaScript to do this because the patch may receive two messages at exactly the same time (I’m building a mini-Schwarzonator for major and minor keys in Max for Live and it will need to handle quantized chords) and whenever I try sending JavaScript two messages at once everything, predictably, crashes.

Thank you!

Aug 19, 2013 at 8:46pm

Try zl sub

Aug 19, 2013 at 10:36pm

You could also use listfunnel, which takes a list and outputs each element one at time preceded by its index.

Aug 20, 2013 at 3:16am

zl sub will return each index in the max window but only the last index will be viewable within the patch. If you are dealing with multiple occurrences of a value in a list, then your best bet is to combine [zl sub] and [zl group]. great combo… powerful and compact.


– Pasted Max Patch, click to expand. –

You must be logged in to reply to this topic.