Don't modify list while iterating over it.
How to remove items from a list while iterating?
In your case you can construct
Could you provide sample
Finally, you may want to have on third-party package like https://pypi.org/project/ciscoconfparse/
How to remove items from a list while iterating?
In your case you can construct
working_config
directly with list comprehension, while iterating over config
. i.e. no need to create copy and then remove elements from itworking_config = [item for item in config if "GigabitEthernet" in item]Note, there is one more problem - because
row
is a tuple (due to using enumerate
) where first element is row index, and the second element - string resulting from splitting lines in the file, I would expect no elements will be removed.Could you provide sample
config
file in full (i.e. not full content but how it looks unmodified)Finally, you may want to have on third-party package like https://pypi.org/project/ciscoconfparse/
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs