配对从xlrd提取的列表中的IP地址 [英] Pair IP addresses in a list pulled from xlrd
问题描述
我已经使用xlrd从一列(以下数据)中提取数据.我需要将ip地址分组在一起.因此,在输出中紧随其后出现的ip地址属于同一个池,而单个IP地址则在它们自己的池中.例如(10.100.33.183,10.100.33.184)属于(pool1). (Pool6 = 10.100.33.89)
I have used xlrd to pull data from a column (Data Below). I need to group together the ip addressess. So ip address that appear next together in the output belong to the same pool and single ones are in a pool of their own. For example (10.100.33.183,10.100.33.184) belong to (pool1). (Pool6 =10.100.33.89)
我该如何实现所有这些帮助.
How do I go about achieving this all help welcome.
['',``,'','','',``,'','Pool Member IP','','10 .100.33.184(S56723FR6VL01)','10 .100.33.183(S56723FR6VL02) ',',',',',',',',','10.101.33.182(S56723FR6VL03)','10.100.33.181(S56723FR6VL04)',',',', '','','','',``10.100.33.180(S56723FR6VL05)'',``10.100.33.179(S56723FR6VL06)'','','',``,'',``,'',``'' ,'10 .100.33.178(S56723FR6VL07)','10 .100.33.177(S56723FR6VL08)','','','',``,'',``,'','10 .100.33.90(S56723FR6VL09)',' ','','','','','','','','10 .100.33.89(S56723FR6VL0A)','','',``,'',``,'', '','','10.100.33.91(S56723FR6VW01)','','','','','','','','','','','','','''' ,'','','','','','','','','','','','','','','','',' ']
['', '', '', '', '', '', '', 'Pool Member IP', '', '10.100.33.184 (S56723FR6VL01)', '10.100.33.183 (S56723FR6VL02)', '', '', '', '', '', '', '', '10.101.33.182 (S56723FR6VL03)', '10.100.33.181 (S56723FR6VL04)', '', '', '', '', '', '', '', '10.100.33.180 (S56723FR6VL05)', '10.100.33.179 (S56723FR6VL06)', '', '', '', '', '', '', '', '10.100.33.178 (S56723FR6VL07)', '10.100.33.177 (S56723FR6VL08)', '', '', '', '', '', '', '', '10.100.33.90 (S56723FR6VL09)', '', '', '', '', '', '', '', '', '10.100.33.89 (S56723FR6VL0A)', '', '', '', '', '', '', '', '', '10.100.33.91 (S56723FR6VW01)', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
推荐答案
ip_data = ['', '', '', '', '', '', '', 'Pool Member IP', '', '10.100.33.184 (S56723FR6VL01)', '10.100.33.183 (S56723FR6VL02)', '', '', '', '', '', '', '', '10.101.33.182 (S56723FR6VL03)', '10.100.33.181 (S56723FR6VL04)', '', '', '', '', '', '', '', '10.100.33.180 (S56723FR6VL05)', '10.100.33.179 (S56723FR6VL06)', '', '', '', '', '', '', '', '10.100.33.178 (S56723FR6VL07)', '10.100.33.177 (S56723FR6VL08)', '', '', '', '', '', '', '', '10.100.33.90 (S56723FR6VL09)', '', '', '', '', '', '', '', '', '10.100.33.89 (S56723FR6VL0A)', '', '', '', '', '', '', '', '', '10.100.33.91 (S56723FR6VW01)', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
ip_pools = [[]] # it starts as a list with an empty list at its last (and only) index
for ip_address in ip_data[ip_data.index('Pool Member IP')+1:]:
if not ip_address: # ip_address is ''
if ip_pools[-1]: # the last element of ip_pools is NOT an empty list: []
ip_pools.append([]) # for the next ip pool
else: # ip_address is not empty
# ip_pools[-1].append(ip_address) # if you need the whole text
ip_pools[-1].append(ip_address.partition(' ')[0]) # if you just want the number
if [] in ip_pools:
ip_pools.remove([]) # to remove last empty list (if exists)
更正了句子
这篇关于配对从xlrd提取的列表中的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!