Help me!!

beginner zyzhu2000 at gmail.com
Thu Aug 16 21:26:05 CEST 2007


> Some one help me so that
> If ab = [a,b,c,d]
> and cd = [a,c]
> my global list file should be [A,b,C,d]


If there is a lot of entries in the list, I would consider using an
indexed data structure such as dict.

>>> ab=['a','b','c','d']
>>> cd=['a','c']
>>> common=[x.upper() for x in ab if x in cd]
>>> ab_minus_cd=[x for x in ab if x not in cd]
>>> cd_minus_ab=[x for x in ab if x not in cd]
>>> requested_list = common+ab_minus_cd+cd_minus_ab




More information about the Python-list mailing list