Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created April 24, 2020 20:27
Show Gist options
  • Save ZhouYang1993/9308d77f253727c3f0ce7410e9229d0a to your computer and use it in GitHub Desktop.
Save ZhouYang1993/9308d77f253727c3f0ce7410e9229d0a to your computer and use it in GitHub Desktop.
File Handling in Python
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