0

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

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Max721
0

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]
>>>
0

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

0

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?

0

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]);
	}
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.