# How to find index for each sublist

Hi,

I am trying to find a way to get index for each sub-list…I can find maximum but struggling to index for each sub-list,

any help will be appreciated

Use List.Map

Hi Michal,

sorry I don’t have a solution for you but I would just like to point out something very weird. The problem here is not extracting the index from the sublists, which can be done by switching the lacing to longest of indexof node. The problem is that the value that come out from maximum item doesnt work with the indexof node. maybe a bug?

Mostafa: List.MaximumItem is silently converting number to a double.

It should work if you convert it to a Integer:

Hi

thanks for reply but it does not work… unless I am doing sth wrong

That sneaky bastard

that’s great to know,

thanks Gui. This also solves Michal’sproblem

It is so close but not working as I do not use integer in my real example…this was just quick simplification…real problem I have is that I take number with few decimal places…

here is proper version

I don’t think there’s a need to map the list. If you switch the lacing of indexof to longest (right click on the node>lacing>longest) it should work

Thanks a lot Mostafa it works great…without map - problem solved

Mostafa,

Would you be able to explain why it works without List.Map but does not work with it? If you dont have time that cool.

Thank you

Hey Steven,

When you map the node it tries to retrieve the index of the 3 values in each one of the sublists, wich does not work with ootb IndexOf node (case 2 in the screen shot). That’s why you get 3 “-1” in the output of list map.

I am no programing expert, i’m just begining to learn, but i’m pretty sure it has something to do with the way the variables are defined in the IndexOf node. Case 3 and 4 are examples 2 functions that are the same with their variables defined differently.

How to get incidences of boolean list for True only?

so when I have

[0] True

[1] False

[2] True

[0] 0

[1] 2

<br class=“Apple-interchange-newline” />

Steven Hansen:

As an alternative to longest lacing in this case, you would have to use List.Combine.

• List.Combine will take each sublist and combine it with each index.
• List.map will take each sublist and check all three indices. (doesn't work)

thanks a lot!