Skip to content

Instantly share code, notes, and snippets.

@ProjectJYL
Created December 5, 2016 22:53
Show Gist options
  • Save ProjectJYL/b96f13e9727521569e6f117f312a95ac to your computer and use it in GitHub Desktop.
Save ProjectJYL/b96f13e9727521569e6f117f312a95ac to your computer and use it in GitHub Desktop.
Exercise: Given two .txt files that have lists of numbers in them, find the numbers that are overlapping. One .txt file has a list of all prime numbers under 1000, and the other .txt file has a list of happy numbers up to 1000. (If you forgot, prime numbers are numbers that can’t be divided by any other number. And yes, happy numbers are a real …
#File Overlap
f1 = open("Documents\primenumbers.txt", "r")
f2 = open("Documents\happynumbers.txt", "r")
f2_list = f2.readlines()
result = list()
for line in f1:
if line in f2_list:
result.append(line.strip() )
f1.close()
f2.close()
print result
@Dishanka13
Copy link

tried with this program but not working

@varunsonavni8487
Copy link

tried with this program but not working

I think you haven't written the necessary information into the file like prime number and happy number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment