Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (45.3k points)

I am trying to check if a dictionary is empty but it doesn't behave properly. It just skips it and displays ONLINE without anything except displaying the message. Any ideas why?

 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())) 

1 Answer

0 votes
by (220 points)
dict = {}
print(len(dict.keys()))

if length is zero means that dict is empty

Related questions

0 votes
1 answer
0 votes
4 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...