우선이 항목은 채팅 봇용 코드입니다. 나는 봇에게 추적 할 단어 목록을 제공하고 있으며, 그 다음에 나는 방 안에있는 모든 메시지를 나눌거야. 이제 다음과 같이 만들어야합니다.Python을 사용하는 2 목록에 있는지 확인하는 방법
하지만 모든 시도가 실패했습니다. 이것이 내 코드입니다. 그러나 내가 완전히 일을 설정하고 난 그냥 내 문제를 봤하고이 문제를 해결 바라고 세트로 내 목록 (예, 모두 나열하지 dicts이 있습니다)로 변환하는 방법을 이해하지 못하는 이론적으로 작동합니다
leyendotracker = open("listas\eltracker.txt", "r") #Open file with tracker words
buffertracker = leyendotracker.read() #Read words and save them in a variable
leyendotracker.close() #Close file
s1tracker = set(message.body.split()) #Set the messages in chat as a Set
s2tracker = set(buffertracker) #Set the variable with words from file as a Set
if s2tracker in s1tracker: #Check if any word from the file is in the message from chat.
print("[TRACKER - "+user.name+" said: "+message.body)
, 문제. 그럼에도 불구하고, 나는이 문제를 다루는 1 시간 후에 항복한다.
내가 무엇이 누락 되었습니까?
intersection(other, ...)
set & other & ...
Return a new set with elements common to the set and all others.
if s2tracker & s1tracker:
# do smth
uhm ....이 3 줄의 코드를 시도했습니다 : # 1 trackeado = filter (lambda word : buffertracker, message.body.split()) # 2 trackeado가 아닌 경우 == None : # 3 print ("Test") 그러나 내 목록의 단어를 무시하고 모든 것을 저장하고있었습니다. – Saelyth
잠깐, 다시 읽었습니다. 대신 IF 사실을 넣어야합니다. 그렇지 않으면? – Saelyth
항상 가져 오는 중 : <0x03369DF0의 필터 개체 > – Saelyth