Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def file_to_list(fname):
f = open(fname)
lst = f.readlines()
return [line.rstrip('\n') for line in lst]
def list_to_file(fname, lst):
f = open(fname, "w")
def remove_from(list_from, list_source):
"""Remove every element in list_from
that exists in list_source"""
result = list(list_from)
for el in list_from:
if el in list_source:
print el
return result
subscribers = file_to_list('subscribers.txt')
users = file_to_list('users.txt')
unsubscribers = file_to_list('unsubscribers.txt')
users_non_subscribers = file_to_list('users_non_subscribers.txt')
# Users who are not subscribers
list_to_file('users_non_subscribers.txt', remove_from(users, subscribers))
# Subscribers who are not users
list_to_file('subscribers_non_users.txt', remove_from(subscribers, users))
# later
#list_to_file('test.txt', remove_from(users_non_subscribers, unsubscribers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.