2013年8月1日 星期四

[Python ] Compare two list only return matched

list1 = [1, 2, 3]
list2 = [3, 4, 5, 6]
# method 1
print list(set(list1) & set(list2))
# method 2
print [d for d in list1 if d in list2]
Related Posts Plugin for WordPress, Blogger...