【问题标题】:Python: Checking if a 'Dictionary' is empty doesn't seem to workPython:检查“字典”是否为空似乎不起作用
【发布时间】:2023-04-06 13:36:02
【问题描述】:

我正在尝试检查字典是否为空,但它的行为不正常。它只是跳过它并显示 ONLINE 除了显示消息之外没有任何内容。任何想法为什么?

def isEmpty(self, dictionary):
    for element in dictionary:
        if element:
            return True
        return False

def onMessage(self, socket, message):
    if self.isEmpty(self.users) == False:
        socket.send("Nobody is online, please use REGISTER command" \
                 " in order to register into the server")
    else:
        socket.send("ONLINE " + ' ' .join(self.users.keys()))    

【问题讨论】:

标签:
python
dictionary