BenWall Posted September 9, 2019 Share Posted September 9, 2019 (edited) Hi, In Python, we can create a "quick array" with conditions in a single line: a1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] a2 = [0, 2, 4, 6, 8] a3 = [i for i in a1 if i not in a2] >>>> a3 == [1, 3, 5, 7, 9] In vex, I know how to do it the long way: int a1[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; int a2[] = [0, 2, 4, 6, 8]; int a3; foreach( int i; a1 ){ if( find(a2, i) >= 0 ){ append(a3, i); } } >>>> a3 == [1, 3, 5, 7, 9] Is there a faster way to do this kind of things, maybe like in Python? Thanks! Edited September 9, 2019 by BenWall Quote Link to comment Share on other sites More sharing options...
Neon Junkyard Posted September 10, 2019 Share Posted September 10, 2019 List comprehension? Not really... Foreach is in itself shorthand, for( int i = 0; i< len(a1); i++). You could create a custom VEX function library for stuff like this, close as you will get to python classes Quote Link to comment Share on other sites More sharing options...
BenWall Posted September 13, 2019 Author Share Posted September 13, 2019 (edited) Too bad! Anyway, I recently learned recently we can do this, which is easier to read to me: if( find(a2, i) >= 0 ){ append(a3, i); } if( find(a2, i) >= 0 ) append(a3, i); Thanks for your answer. Edited September 13, 2019 by BenWall 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.