写出来了import re
list = ['xgei-0/0/0/1 optical Duplex/full 10000 up up up UT-[HW', '-RT01-NE5000E]', '-Gig-11/0/0-10G', 'xgei-0/0/0/2 optical Duplex/full 10000 up up up UT-[HW', '-RT02-NE5000E]', '-Gig-1/10/2/3-10', 'G', 'xgei-0/0/0/3 optical Duplex/full 10000 down down down UT-[HW', '-RT01-NE5000E]', '-Gig-1/0/4-10G']
target_list = []
for i in range(len(list)):
max_len = len(list)
if 'up' in list[i] or 'down' in list[i]:
port_info = list[i]
# print(port_info)
j = i
while re.search('up', list[j + 1]) == None and re.search('down', list[j + 1]) == None:
port_info = port_info + list[j + 1]
j = j + 1
j = max_len
break
target_list.append(port_info)
print(target_list)
|