I am working on below output that i received from earlier config
['Te1/1/1', 'server', 'Ten', 'connected', 'trunk', 'full', '10G', '10Gbase-LR']
['Te1/1/2', 'desc', 'connected', 'trunk', 'full', '10G', '10Gbase-LR']
['Gi1/2/1', 'desc', 'disabled', 'routed', 'full', '1000', 'No', 'Transceiver']
['Gi2/1/2', 'disabled', 'routed', 'full', '1000', 'No', 'Transceiver']
['Te2/2/1', 'server', 'notconnect', '301', 'full', '10G', '10Gbase-LR']
['Po120', 'notconnect', 'unassigned', 'auto', 'auto']
['Po121', 'notconnect', '1', 'auto', 'auto']
What I want is to remove any string from the list till string "connected" or "disabled" or "notconnect" is found except 1st item.
I had tried below configuration:
regex_chk = re.compile("((?:not)*?connect(?:ed)*|disabled|)")
for item in items:
for i in item[1:]:
if i != regex_chk:
item.remove(i)
print(item)
result comes as:
['Te1/1/1']
['Te1/1/2']
['Gi1/2/1']
['Gi2/1/2']
['Te2/2/1']
['Po120']
['Po121']
Whereas I want the result to be
['Te1/1/1', 'connected', 'trunk', 'full', '10G', '10Gbase-LR']
['Te1/1/2', 'connected', 'trunk', 'full', '10G', '10Gbase-LR']
['Gi1/2/1', 'disabled', 'routed', 'full', '1000', 'No', 'Transceiver']
['Gi2/1/2', 'disabled', 'routed', 'full', '1000', 'No', 'Transceiver']
['Te2/2/1', 'notconnect', '301', 'full', '10G', '10Gbase-LR']
['Po120', 'notconnect', 'unassigned', 'auto', 'auto']
['Po121', 'notconnect', '1', 'auto', 'auto']