Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Latest commit

 

History

History
30 lines (26 loc) · 633 Bytes

is-empty.md

File metadata and controls

30 lines (26 loc) · 633 Bytes
title type tags author cover dateModified
Collection is empty
snippet
list
dictionary
string
chalarangelo
salad-1
2023-01-12 05:00:00 -0400

Checks if the a value is an empty sequence or collection.

  • Use not to test the truth value of the provided sequence or collection.
def is_empty(val):
  return not val
is_empty([]) # True
is_empty({}) # True
is_empty('') # True
is_empty(set()) # True
is_empty(range(0)) # True
is_empty([1, 2]) # False
is_empty({ 'a': 1, 'b': 2 }) # False
is_empty('text') # False
is_empty(set([1, 2])) # False
is_empty(range(2)) # False