我有两个包含IP地址的词典。 E.g
site_scope1 = {'Servers': ['1.1.1.1', '1.1.1.2']}
和另一个包含从看起来像
的设备中提取的地址vlan_helpers = {'300': ['1.1.1.1', '1.1.2.2']}
如何比较两个词典以验证vlan_helpers中的300键是否包含site_scope1中Servers键中的值?
答案 0 :(得分:1)
使用set个对象:
result = set(site_scope1['Servers']) == set(vlan_helpers['300'])
答案 1 :(得分:0)
您可以在 <script src="js/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="js/jquery/bootstrap/bootstrap.js" type="text/javascript"></script>
<script src="js/jquery/stupidtable.js" type="text/javascript"></script>
<script src="js/jquery/jquery-ui-1.9.2.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<link href="js/jquery/bootstrap/bootstrap.css" rel="stylesheet" />
<link href="js/jquery/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
<link href="css/admin/main.css" rel="stylesheet" />
<script src="js/admin/main.js" type="text/javascript"></script>
<script src="js/admin/item.js" type="text/javascript"></script>
<link href="helpers/uploadfy/css/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="helpers/uploadfy/js/swfobject.js"></script>
<script type="text/javascript" src="helpers/uploadfy/js/jquery.uploadify.v2.1.4.min.js"></script>
<script>
$(document).ready(function() {
$('#fupload').uploadify({
'uploader' : 'helpers/uploadfy/js/uploadify.swf',
'script' : '[baseUri]/admin/uploadr/[item_id]/',
//'cancelImg' : 'helpers/uploadfy/js/cancel.png',
'cancelImg' : 'images/icons/cancelb.png',
'folder' : 'app/fotos',
'auto' : true,
'multi' : true,
'buttonText' : 'Upload',
'sizeLimit' : 25002400,
'width' : 275,
'height' : 40,
//'queueSizeLimit' : 10,
'uploadLimit' : 1,
'fileExt' : '*.jpg;*.gif;*.png;*.bmp;*.jpeg',
'fileDesc' : 'Imagens (JPG, GIF, PNG, BMP)',
//'buttonImg' : 'helpers/uploadfy/upload.png',
'buttonImg' : 'images/icons/uploadr.png',
'onAllComplete': function(event, queueID, fileObj,response){
reloadFotoBind();
},
'onComplete': function(event, queueID, fileObj,response){
var response = $.parseJSON(response);
$(response).each(function(k,v){
if(v.id != 'error'){
$('<li id="li_'+v.id+'"><img src="[baseUri]/thumb/'+v.url+'/130/100/" id="img_'+v.id+'"/></li>').appendTo('#photo-gallery-ul');
}else{
$('<li>erro</li>').appendTo('#photo-gallery-ul');
}
})
//window.location = '[baseUri]/admin/item/editar/[item_id]/fotos/';
}
})
})
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
中找到Serveurs
中的哪一个:
300
答案 2 :(得分:0)
据我了解你的问题,你只想比较字典中的两个specific
元素。
site_scope1 = {'Servers': ['1.1.1.1', '1.1.1.2']}
vlan_helpers = {'300': ['1.1.1.1', '1.1.2.2']}
print(site_scope1['Servers'] == vlan_helpers['300'])
输出:
False
如果您的IP未被订购,请使用set()
:
print(set(site_scope1['Servers']) == set(vlan_helpers['300']))`
答案 3 :(得分:0)
要检查两个键是否具有相同的值,您可以直接访问它们并以这种方式进行比较:
if site_scope1['Servers'] == vlan_helpers['300']:
# Do something.
如果您只是想检查服务器列表中的某些键是否也在300列表中,您可以这样做:
for item in site_scope1['Servers']:
if item in vlan_helpers['300']:
print('IP is in Both dicts: ', item)