def read_file(filename):
    with open(filename) as data:
        accounts = defaultdict(set)
for line in data:
    IP, username = line.split()[:2]
accounts[username].add(IP)
print('The accounts will be deleted from memory in 5 seconds')
time.sleep(5)
accounts.clear()
print('The accounts have been deleted from memory')
time.sleep(5)
print('End of script')
if __name__ == '__main__':
    read_file('ips.txt')
How to free memory after opening a file in Python