Skip to content

Instantly share code, notes, and snippets.

@hackerdem
Created April 18, 2016 07:27
Show Gist options
  • Save hackerdem/0982b128145b24a4e5fb4513e2cd907f to your computer and use it in GitHub Desktop.
Save hackerdem/0982b128145b24a4e5fb4513e2cd907f to your computer and use it in GitHub Desktop.
given to list of numbers, from a website, which contain happy numbers and prime numbers, find common 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