如何比较不同类别的2套和列表?

时间:2019-07-11 14:49:04

标签: python list class

我有一个来自People类的集和一个来自城市集的列表,其中包括当前附加到该列表的人员的ID。我正在尝试比较设置的commonf,并查看PHere列表中是否有这些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

我希望,如果他们在这两个信息站中,一旦他们在同一个城镇中,就会互相提醒。然后,一旦其中一个离开,就再次提醒对方。

0 个答案:

没有答案