Skip to content

Instantly share code, notes, and snippets.

@hackerdem
Last active April 6, 2016 13:42
Show Gist options
  • Save hackerdem/8172ceca25b96f563fde to your computer and use it in GitHub Desktop.
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.
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