Created
April 18, 2016 07:27
-
-
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
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