A-List of Unhashable Types

0
409
JavaScript 1624952792
javascript, programming, logo @ Pixabay

The unhashable types list is a list of all the different types that are unhashable. Some you may have heard about, but others might be more obscure. This list includes types like:

strings

numbers

booleans

objects

arrays

nulls

undefined values

This list doesn’t include types like:

dates and times (which are unhashable)

Or types that can be easily converted to hashable types. This list also includes some examples of what the different items may look like in JavaScript or Python code, with a description of the type

String: A string is anything that consists only of letters, numbers, symbols, and spaces. This can be a word or even just one letter

This example shows what strings might look like in JavaScript code with how to determine if it’s an empty string or not (!= “).

JavaScript: if (str !== “”) {} else {}; // empty string, do something with it.

Python: print(“string is not empty”); if str == “” : ~ Comment to end of line for a comment in JavaScript or Python code*~ endif; #!/usr/bin/python

Boolean: A boolean is one of the types that can be either true or false.

This example shows how to determine if a variable called “x” is equal to 0 (false) or not (!=0). It then prints out what type it was as well, for reference and debugging purposes.

JavaScript 1624952762
technology, computer, code @ Pixabay

JavaScript: if (x !== 0) {}; // boolean

This is how a list of types can look in JavaScript.

Python: for x in range(0, 100): # Do something with all the numbers in this array . print(“boolean”); break; # End loop and go to next type statement*

JavaScript: for x in range(0, 100): # Do something with all the numbers in this array . print(“array”); break; # End loop and go to next type statement*

Python: list = [] # Create an empty list called “list”. This is how you would initialize it. echo(“List”)

JavaScript: var list = []; # Create an empty list called “list”. This is how you would initialize it. echo(“Array”);

Python: map = {} # Create a blank dictionary, which stores key-value pairs . (For more information on dictionaries in Python, see the Dictionaries section below.) scream(“Dictionary”)

JavaScript: var map = {}; # Create a blank dictionary, which stores key-value pairs . (For more information on dictionaries in JavaScript, see the Dictionaries section below.) echo(“Map”);

Python: class Animal(object): def __init__(self, name, date_of_birth): self.name = name # Create a list of attributes for the Animal class. self._birthdate = date_of_birth

JavaScript: var Animal = function(name, birthDate) { this.name=name; }  this.__init__(); // Define an “init” method that will initialize the Animal’s name and birth date.

JavaScript 1624952818
programmer, computer, woman @ Pixabay

Python: class Text(object): def __init__(self, message): self._message = message  self.created_at = None # Define an “init” method that will initialize the text object with a string value for its content and current timestamp as null (None).

JavaScript: var Text = function(message) { this.message= message; }  this.__init__(); // Define an “init” method that will initialize the text object with a string value for its content and current timestamp as null (None).

Python: class ListItem(object): def __init__(self, text): self._text = text  self.created_at= None # Define an “init” method that will initialize the listitem object with a string value for its content and current timestamp as null (None).

JavaScript: var ListItem = function(text) { this.text= text; }  this.__init__(); // Define an “init” method that will initialize the listitem object with a string value for its content and current timestamp as null (None).

Python: class UnhashableType(object): def __init__(self, text): self._text = text  self.created_at= None # Define an “init” method that will initialize the listitem object with a string value for its content and current timestamp as null (None).

JavaScript: var UnhashableType = function(text) { this.text= text; }  this.__init__(); // Define an “init” method that will initialize the listitem object with a string value for its content and current timestamp as null (None).