Skip to content

Instantly share code, notes, and snippets.

@umair-tp
Created February 27, 2018 11:09
Show Gist options
  • Select an option

  • Save umair-tp/113cfeac14283896047da34a38912183 to your computer and use it in GitHub Desktop.

Select an option

Save umair-tp/113cfeac14283896047da34a38912183 to your computer and use it in GitHub Desktop.
Exercise 23 : 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 r…
with open('primenumbers.txt') as prime_file:
prime_nums = prime_file.read().split('\n')
with open('happynumbers.txt') as happy_file:
happy_nums = happy_file.read().split('\n')
for prime_num in prime_nums:
if prime_num in happy_nums:
print prime_num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment