gerardocastellanos Posted October 13, 2019 Share Posted October 13, 2019 Hello how can I query if an element is in a list or not? in python is " if element in list: " thanks you. Quote Link to comment Share on other sites More sharing options...
anim Posted October 13, 2019 Share Posted October 13, 2019 You can use find() function, if the resulting index is negative, element is not in the array Quote Link to comment Share on other sites More sharing options...
gerardocastellanos Posted October 13, 2019 Author Share Posted October 13, 2019 thans you! Quote Link to comment Share on other sites More sharing options...
gerardocastellanos Posted October 13, 2019 Author Share Posted October 13, 2019 (edited) I stored different index (integer number) in my primitives, and I want to create an array detail attribute with all my different index. sometimes my geometry could has 4 different index, for example (3,6,7,2), but in another case it could has 6 or 8 different numbers. my idea is store in a detail attribute that list of numbers (index) I create an primitive wrangle with this: int indexList[] = detailattrib(0, "indexList",0,1); if (!find(indexList, @index)){ push(indexList, (int)@index); setdetailattrib(0, "indexList", indexList); } but it does not work as I expect. what I am doing wrong? thanks Edited October 13, 2019 by gerardocastellanos Quote Link to comment Share on other sites More sharing options...
anim Posted October 13, 2019 Share Posted October 13, 2019 (edited) as I mentioned if returned index by find() is negative it's not found your test simply tests if it's 0, which is actually still a valid index so you want to do : if (find(indexList, @index) < 0) Edited October 13, 2019 by anim Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.