Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lists
#4
This seems to work a bit better:

# declare an empty list

config = []


# open the file

with open(r"c:\\Temp\python\switch\switch.txt", mode='r') as f:
 #   switchports = f.read().split('!')
    
     for switchports in f.read().split('!'):
        config.append(switchports)


# create a copy of the list

working_config = [item for item in config if "GigabitEthernet" in item]
Now I get 196 for the len of config

and 31 for the len of working_config

I can see information in the working_config list, but it looks like all the indexes contain the same information
Reply


Messages In This Thread
Lists - by blake7 - Oct-06-2023, 11:22 AM
RE: Lists - by buran - Oct-06-2023, 11:37 AM
RE: Lists - by blake7 - Oct-06-2023, 11:54 AM
RE: Lists - by blake7 - Oct-06-2023, 12:08 PM
RE: Lists - by buran - Oct-06-2023, 12:09 PM
RE: Lists - by buran - Oct-06-2023, 12:29 PM
RE: Lists - by buran - Oct-06-2023, 12:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 3,294 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 5,029 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020