Last active
April 6, 2016 13:42
-
-
Save hackerdem/8172ceca25b96f563fde to your computer and use it in GitHub Desktop.
A python script to find the numbers which are both happy number and prime number from two files containing these numbers.
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
import urllib.request | |
# get data | |
def get_data(target): | |
listo=[] | |
response=urllib.request.urlopen(target).read().decode('utf-8').split('\n') | |
for line in response: | |
listo.append(line) | |
return listo | |
#find common values | |
def find_intersection(data): | |
return list(set(data[0])&set(data[1])) | |
#main function | |
if __name__=='__main__': | |
data=[] | |
target=['http://www.practicepython.org/assets/happynumbers.txt','http://www.practicepython.org/assets/primenumbers.txt'] | |
for i in range(len(target)): | |
data.append(get_data(target[i])) | |
print(find_intersection(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment