How to get list of indices?

I have long list with sub-list. All I need is new list of indices for all none empty sublists…

so in this case result would be list {45} as this is only none empty sub-list…

For some reason using List.AllIndicesOf doesn’t work, but you could also do this:

2 Likes

@Michal_Dengusiak

Another solution:

Thanks salvatoredragotta

How to modify this script that will check if number is more than 0 and the display indices?

I tried to modified but sth did not work

@Michal_Dengusiak
What’s the error?
Not sure if I understand, you want to list all the indexes?
If so, get rid of the “if”

thanks for your help, first script was working perfectly…
I tried to modify and get it working for another issue but without success

my results should be only [24] as this is the only case where value of sublist >0
my script does not work as I have indexes of all which is wrong

I managed to do messy way…

Maybe this helps:

You need the list lenght = len(i) as Salvatore shows in his code. You can also simply use if i.

Do we know why List.AllIndicesOf does not work ?
I had this problem recently & thought I was doing something wrong

Andrew

Not sure why your are trying to modify the “if” part of the code to achieve the same result.

“i” in the code is a list. if you want to extract all lists that are not empty you can use the code I suggested which check is the length of the list is not equal to 0. Or as @Organon suggested just write “if i” (a list which is not empty is by definition True).
But i>0 won’t work.

In the example below 1& 2 do exactly the same thing. 3 gives you how many items are in the each list. (I’m just shortened the code using list comprehension this time).

I hope this helps.

Hi,

sorry just to clarify…when I did i>0 I was meaning value of sublist not lenght… so if any value of sublist is >0 then return index

Hi, @Michal_Dengusiak

I got it now :relaxed:

Try this: