code_junkie

Python: What is the best way to check if a list is empty?

Nov 10th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. a = []
  2.  
  3. if not a:
  4. print "List is empty"
  5.  
  6. if not seq:
  7. if seq:
  8.  
  9. if len(seq)
  10. if not len(seq)
  11.  
  12. a = []
  13. if a:
  14. print "not empty"
  15.  
  16. if not a:
  17. print "The list is empty or null"
  18.  
  19. if a == []:
  20. print "The list is empty."
  21.  
  22. if len(li) == 0:
  23. print 'the list is empty'
Add Comment
Please, Sign In to add comment