The preferred way to check if any list, dictionary, set, string or tuple is empty in Python is to simply use an if statement to check it. For example, if we define a function as such: It will magically detect if any built in structure is empty. So if we run this: Then, if we [...]
Articles Tagged: dict
How to Implement an ‘enum’ in Python
What is enum and why we need it An enumerated type, a.k.a. enum, is a data type consisting of a set of named values called elements, members or enumerators of the type. These enumerated named values function as constants in the computing language. For example, a COLOR enum may include named values such as RED, [...]
How to Sort Python Dictionaries by Key or Value
Note: If you want to sort a list, tuple or object in Python, checkout this article: How to Sort a List or Tuple in Python The dict (dictionary) class object in Python is a very versatile and useful container type, able to store a collection of values and retrieve them via keys. The values can be objects of any type [...]
Python Dictionary
The Python Dictionary (dict): An Overview Among the built-in Python data types is a very versatile type called a dictionary. The dictionary is similar to lists and tuples because they act as storage units for other objects or variables you’ve created. Dictionaries are different from lists and tuples because the group of objects they hold [...]