Chcę znaleźć użytkowników, którzy nie obserwują mnie na Instagramie. Mam dwa pliki txt

iamfollowing.txt
jhon
mike
dennis
pluto44
hunter34

floowingme.txt
dennis
pluto44

Chcę to wyjście

Dontfollowback.txt
jhon
mike
hunter34

-2
Serhat A 2 kwiecień 2020, 10:43

3 odpowiedzi

Najlepsza odpowiedź
with open('iamfollowing.txt', 'r') as f:
    iamfollowing = [name.strip() for name in f.readlines()]

with open('followingme.txt', 'r') as f:
    followingme = [name.strip() for name in f.readlines()]

notfollowing = [name for name in iamfollowing if name not in followingme]

print(notfollowing)
0
Oleg Ivanytskyi 2 kwiecień 2020, 07:51

Spróbuj tego:

with open('iamfollowing.txt', 'r') as ff:
    iamfollowing = ff.readlines()

with open('floowingme.txt', 'r') as fm:
    followingme = fm.readlines()

not_following_me = [p for p in iamfollowing if p not in followingme]

0
Gabip 2 kwiecień 2020, 07:54

Oto pseudokod do tego (służy tylko do planowania stanu, takiego jak schematy blokowe) -

file1 = open('iamfollowing.txt', 'r')
file2 = open('floowingme.txt', 'r')

list_file1 = []
for line in file1:
    list_file1.extend([x for x in line.split()])

lst = []
for line in file2:
    for word in list(line.split()):
        if word not in list_file1:
            lst.append(word)

print(lst)
0
Abhijeet.py 2 kwiecień 2020, 07:56