Skip to content

Instantly share code, notes, and snippets.

@aymanfarhat
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aymanfarhat/e63c0dcb378b356aa7e0 to your computer and use it in GitHub Desktop.
Save aymanfarhat/e63c0dcb378b356aa7e0 to your computer and use it in GitHub Desktop.
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")
f.write("\n".join(lst))
f.close()
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
result.remove(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