Created
April 24, 2020 20:27
-
-
Save ZhouYang1993/9308d77f253727c3f0ce7410e9229d0a to your computer and use it in GitHub Desktop.
File Handling in Python
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 bisect | |
| with open('ip1.txt', 'r') as f1: | |
| list1 = [line.rstrip('\n') for line in f1.readlines()] | |
| with open('ip2.txt', 'r') as f2: | |
| list2 = [line.rstrip('\n') for line in f2.readlines()] | |
| list2.sort() | |
| same_ip = [] | |
| for i in list1: | |
| position = bisect.bisect_left(list2, i) | |
| if position < len(list2) and list2[position] == i: | |
| same_ip.append(i) | |
| same_ip = list(set(same_ip)) | |
| print(same_ip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment