如何比较来自不同类的两个集合和列表?

2024-06-25 22:45:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个从人民类和一个从镇集合,其中包括目前附加到该列表的人的ID列表集1集。我正在尝试比较set mutualf,看看这些id是否在列表中。一旦完成,提醒两个共同的朋友他们在同一个城市,然后再次提醒他们中的一个“离开”

def alertMutual(self):
    return

def checkMutual(self):
    for i in len(self.Town.PHere):
        x = Town.findPer(self, self.mutualf)
        if x in self.mutualf: self.alertMutual()
        else:return

我被困在警报过程中,不确定这是工作,我认为它应该是

class People:
    '''People to make friendships, have a name, and a unique ID'''

    numsTimes = 0  ###Class variable for ID

    def __init__(self, name="anon"):
        if name == "anon":
            self.myname = makeRName()  ####Random Name
        else:
            self.myname = name
        self.friends = {}  ####Empty List so people will be able to make friends
        self.mutualf = {}

     def makeMutual(self, other):
        mutual = self.friends.intersection(other.friends)
        self.mutual.add(mutual)
        self.friends.remove(mutual)

class Town:
    '''To hold people, have a name, and a unique ID'''

    numsTimes = 0  # Class variable for ID

    def __init__(self, tname="anon", maxPpl=-1):

        self.PHere = [[]]  ####Hold People

        self.tID = Town.numsTimes  ###Unique ID
        Town.numsTimes += 1

        if self.Maxppl == -1:
            self.Maxppl = randint(2, 15)  ####Each town gets individual maximum of People to hold
        else:
            self.Maxppl = MaxPpl

我预计,如果他们在两个sts的信息,它会提醒对方,一旦他们在同一个城市。一旦他们中的一个走了,再提醒对方


Tags: tonameselfid列表forifdef