python - 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)
解决方案
推荐阅读
- javascript - 使用 lodash 或 ramda 转换对象数组
- networking - 页面在有机会呈现之前重新加载
- emacs - 我什么时候应该使用`require`一个`autoload`的包?
- eclipse - 如何使用 Scala 2.11 代码获取在 shell (bash) 脚本文件中定义的属性值?
- reactjs - React - 如何打破“ React.Children.forEach ”循环?
- python-3.x - 为每个 pandas 行创建一个包含接下来 10 个行列值的向量
- asp.net-mvc - 没有重定向 AAD RedirectUri 的 OWIN MVC5
- node.js - 使用 Ember.js 插件在 WebStorm 中创建新的 Ember 项目时卡住了
- sql - 在数据库中填充新表的最佳方法
- javascript - 无法使用 MySQL 和 ReactJS 显示行