Hi,

A= [1,3,5]
B=[12,24,36,48,60,72]

Here list A is a list of the elements in list B i want to remove. How can I do this so that I would get list B to then look like:

B=[12,36,60]

Thanks in advance,
Zach

Remove an item from a list:

>>> B = [12,24,36,48,60,72]
>>> B.remove(24)
>>> B.remove(48)
>>> B.remove(72)
>>> B
[12, 36, 60]
>>>

Thanks for your help. I did know how to do that already but what I was trying to do was do it automatically as list A and list B could be anything!

Thanks for your reply and help! z

EDIT: I see what you're doing now... in your code above, you have a mistake... it should be for x in A instead of for x in B , right?

If you are removing elements from array B according to A code should look like this

int A[]={1,3,5};
	int B[]={12,24,36,48,60,72};
	int C[3]={0,0,0};
	int length =sizeof(A)/sizeof(A[0]);
	for (unsigned int i=0;i<length;i++)
	{
		C[i]=B[A[i]-1];
		printf("%d ",C[i]);
	}

If you are removing elements from array B according to A code should look like this

int A[]={1,3,5};
	int B[]={12,24,36,48,60,72};
	int C[3]={0,0,0};
	int length =sizeof(A)/sizeof(A[0]);
	for (unsigned int i=0;i<length;i++)
	{
		C[i]=B[A[i]-1];
		printf("%d ",C[i]);
	}

It's true, but this is the python forum, not the C forum :)

This question has already been answered. Start a new discussion instead.