小编abc*_*abc的帖子

Python添加两个集合并删除重复元素

如何添加两组并删除重复项

>>> a = set(['a', 'b', 'c'])
>>> b = set(['c', 'd', 'e'])
>>> c = a + b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'set' and 'set'
>>>

Expected output:
c = set(['a','b','c', 'd', 'e']) 
Run Code Online (Sandbox Code Playgroud)

python python-2.7

7
推荐指数
1
解决办法
4910
查看次数

集合列表找到两个列表python的区别

下面是代码,比较两个列表,我已经使用了集合,因为我很好,如果元素位置不同.脚本检查list2包含list1中包含的所有元素.这工作正常.现在,我需要帮助将list1与list2进行比较时缺少的内容或有什么区别.

list1 =  ['ab','cd','600','4','a=7777','b=7777']
list2 = ['ab', 'cd','600', '4','a=7777','b=7777']
if collections.Counter(list1) != collections.Counter(list):
   print "something not matching  or missing list1 with list2"
   print "help me what is missing or what different values between list1 and list2"
Run Code Online (Sandbox Code Playgroud)

预期产量:

   if 
   list1 =  ['ab','cd','600','4','a=7777','b=7777']
   list2 = ['ab', 'cd','600', '4','a=7777','b=7777']

   Expected output:
   Do Not print anything.


   elif
   list1 =  ['ab','cd','600','4','a=7777','b=7777']
   list2 = ['ab', 'cd','600', '4','a=7777','b=77']
   Expected output:
   print "MisMatch"
   print "In list2 b=7777 should contain"

   elif
   list1 =  ['ab','cd','600','4','a=7777','b=7777']
   list2 = ['ab', 'cd','600','a=7777','b=7777']
   Expected …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

1
推荐指数
1
解决办法
73
查看次数

标签 统计

python ×2

python-2.7 ×2