Last active
August 29, 2015 14:03
-
-
Save aymanfarhat/e63c0dcb378b356aa7e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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