試圖從在Python中設置的列表中刪除重複的用戶。問題是,它不刪除重複的用戶:使用set()從列表中刪除重複的用戶
with open ('live.txt') as file:
for line in file.readlines():
word = line.split()
users = (word[word.index('user')+1])
l = users.split()
l = set(l)
l = sorted(l)
print " ".join(l)
這裏是live.txt
內容:
Sep 15 04:34:24 li146-252 sshd[13320]: Failed password for invalid user ronda from 212.58.111.170 port 42201 ssh2
Sep 15 04:34:26 li146-252 sshd[13322]: Failed password for invalid user ronda from 212.58.111.170 port 42330 ssh2
Sep 15 04:34:28 li146-252 sshd[13324]: Failed password for invalid user ronda from 212.58.111.170 port 42454 ssh2
Sep 15 04:34:31 li146-252 sshd[13326]: Failed password for invalid user ronda from 212.58.111.170 port 42579 ssh2
Sep 15 04:34:33 li146-252 sshd[13328]: Failed password for invalid user romero from 212.58.111.170 port 42715 ssh2
Sep 15 04:34:36 li146-252 sshd[13330]: Failed password for invalid user romero from 212.58.111.170 port 42838 ssh2
這應該一次性activity.There不應該需要一個循環 – vks 2015-02-24 08:47:42
爲'users'請新增樣本值! – 2015-02-24 08:47:43
你介意在這裏添加你的用戶嗎?預計輸出什麼 – 2015-02-24 08:52:39