remove a list from a list
J. Clifford Dyer
webmaster at cacradicalgrace.org
Mon Nov 20 14:32:16 EST 2006
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
More information about the Python-list
mailing list