Jump to content

Handling array in Vex


BenWall

Recommended Posts

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 by BenWall
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...