By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,495 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

remove a list from a list

P: n/a
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

Nov 17 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Rares Vernica wrote:
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
Nov 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.