remove a list from a list

R

Rares Vernica

Hi,

I have the following problem:

I have a list like
e = ['a', 'b', 'e']
and another list like
l = ['A', 'a', 'c', 'D', 'E']
I would like to remove from l all the elements that appear in e
case-insensitive. That is, the result would be
r = ['c', 'D']

What is a *nice* way of doing it?

Thanks a lot,
Ray
 
J

J. Clifford Dyer

Rares said:
Hi,

I have the following problem:

I have a list like
e = ['a', 'b', 'e']
and another list like
l = ['A', 'a', 'c', 'D', 'E']
I would like to remove from l all the elements that appear in e
case-insensitive. That is, the result would be
r = ['c', 'D']

What is a *nice* way of doing it?

Thanks a lot,
Ray

if you can guarantee that e will always be made up of lowercase letters,
then you can do the following:

r = [ x for x in l if x.lower() not in e ]

Cheers,
Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top