首页 > 解决方案 > Python List:选择各自索引的两个列表

问题描述

list1 = ['ibsdr1', 'ibsds1', 'ibsds1', 'ibsdm2', 'ibsdm2', 'ibsdm2']

list2 = ['Gig 0/0/1', 'Gig 6/47', 'Gig 5/47', 'Gig 6/7', 'Gig 6/3', 'Gig 5/3']

我有两个列表,我需要在list1具有相应端口的每个设备上运行以下脚本list2

list1[0]. 应该只选择list2[0],它不应该选择其余的list2

每个列表索引都应该只选择它们各自的索引。

ibsdr1 should select Gig 0/0/1
ibsds1 should select Gig 6/47
ibsds1 should select Gig 5/47
ibsdm2 should select Gig 6/7
ibsdm2 should select Gig 6/3
ibsdm2 should select Gig 5/3

下面是我试图运行的脚本,但我没有得到正确的输出。索引正在一一list1选择所有索引。list2

for (sw, op) in zip(list1, list2):
    connect = {'device_type': 'cisco_ios', 'ip': sw, 'username': user, 'password': password, 'port': 22}
    net_connect1 = ConnectHandler(**connect)
    opout = net_connect1.send_command_expect('show interfaces '+op+' switchport')
    opp.append(opout)
    print (opp)

标签: pythonpython-3.x

解决方案


推荐阅读