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

OK its now sorted:

A.reverse()
for x in B:
    B.pop(x)

yeah!

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 :)

Ooops my fault :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.