comparing two lists
jimgardener at gmail.com
Fri Mar 5 09:05:18 CET 2010
I have two lists of names.I need to find the difference between these
two lists.I tried to do it using sets.But I am wondering if there is a
better way to do it.Please tell me if there is a more elegant way.
my code snippet follows..
print '%d were newly added= %s'%(len(newlyadded),list(newlyadded))
print '%d were removed=%s'%(len(removed),list(removed))
print '%d were unchanged=%s'%(len(unchanged),list(unchanged))
this produces the output
2 were newly added= ['jaime', 'cersei']
3 were removed=['ned', 'arya', 'bran']
1 were unchanged=['jon']
More information about the Python-list