Created
April 21, 2021 21:01
-
-
Save jimbrayrcp/90fb155536c08e2517155a7bce2df636 to your computer and use it in GitHub Desktop.
Python List Compensation to compare single list of numbers in two text files extracting the matching numbers into a single list
This file contains 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
# # PYTHON LIST COMPENSATION | |
# compare single list of numbers | |
# in two text files extracting the matching numbers into a single list | |
# NOTE: in file1 & file2 the numbers are a single column in each list. | |
with open('file1.txt') as f: | |
file1 = [int(n) for n in f] | |
with open("file2.txt") as f: | |
file2 = [int(n) for n in f] | |
result = [element for element in file1 if element in file2] | |
print(result) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment