The following algorithm is used to open, read, and update a file ("allow_list.txt"). This file contains a list of IP addresses that are allowed to access restricted content.
Initially, a variable is created to hold the name of the file we will be updating. Additionally, another variable is created to store the list of IPs to be removed. This is where our file opening command begins.
After opening and reading the file we save it to a variable named ip_addresses and its contents are printed. Output below:
Use ".split()" to convert the string in ip_addresses to a list. Output below:
Using a for loop to cycle through each element in remove_list. Output below:
Now an if statement is added to the for loop. Using .remove() the IPs in remove_list are eliminated. Output below:
Finally it's time to update the file with the new list of allowed IP addresses. The file is reopened, then written over.
This lab taught me how to open files and edit them using the various commands showcased above.









