找出python列表中重复项的方法,找出python列表重复,假设我有几个列表数据,例


假设我有几个列表数据,例如4个:

list1=['2','5','10']list2=['3','6','8']list3=['7','6','9']list4=['5','4','3']

我如何找到列表中在其他的列表中含有的数据?重复的数据,比如说6在list2和list3都含有。
就打印出来6在list3和list2都包含。

求集合的交集:

>>> set2 = set(list2)>>> set3 = set(list3)>>> print set2 & set 3set(['6'])

其他操作:

>>> x = set('abcde')>>> y = set('bdxyz')>>> xset(['a', 'c', 'b', 'e', 'd'])                    # display format>>> 'e' in x                                      # MembershipTrue>>> x – y                                         # Differenceset(['a', 'c', 'e'])>>> x | y                                         # Unionset(['a', 'c', 'b', 'e', 'd', 'y', 'x', 'z'])>>> x & y                                         # Intersectionset(['b', 'd'])>>> x ^ y                                         # Symmetric difference (XOR)set(['a', 'c', 'e', 'y', 'x', 'z'])>>> x > y, x < y                                  # Superset, subset(False, False)

http://www.cnblogs.com/bears/archive/2012/02/02/2335535.html

编橙之家文章,

评论关闭