What is an unhashable type list?

3D source code of a webpage, open in programming editor's application window. Several planes with data floating in 3d space - central one in focus. Digitally generated background, expressing the technologies behind the internet. Webpage making illustration.

An unhashable type list is a data structure that can be evaluated by hashing but cannot usually be used as input to a hash function. 

It’s also known as a litwish, which was introduced in 1977. All items are contained in an array of immutable objects, with no pointers or references to other items.

If the hash result of the first item is less than this number, then you’re out of luck because all subsequent hashes will fail. 

This makes it impossible to determine if two things are equal without using external memory and reversing the whole thing.


An unhashable type list can be implemented by an array of unassigned memory, but the Hashable interface should still be satisfied by this array. 

Here are some points discussed about unhashable type list

1. Unhashable type list is an immutable data structure.

The first index of a Unhashable Type List is 0, irrespective of the length of the array. The reason behind this choice is that, if we start from 1 then if we hash a known element it will take the value as -1 as 1 > 0, but as I wrote above “if the hash result of the first item is less than this number then you’re out of luck”. 

So to make sure there is no such situation this choice has been made.

In Python 2.7+ and 3.x, an unhashable type list can be implemented using a set instead of an array. However python does not support null terminated string as set elements.

2. Unhashable type list is a good data structure for games.

One of the ideas behind making an unhashable type list is to have some kind of successor system combined with randomisation so that all possible paths through a game or a narrative can be explored. 

To do this, an unhashable type list must store all the possible positions of an element on the list. 

Almost any randomised function can be used to map positions onto elements, including dice rolls and random  number generators.

3. This list is used for randomization in games

Unhashable type list is used for randomization in games, like randomly choosing an element from an unhashable type list. 

Its size is also variable so it can store more than 2 − 1 elements. The way to get the random number of an element, if you are using python , is- def random_element(self): return self.index(random.randint(0, self.size))

4. Unhashable type list is used for representing lists in programming languages

Unhashable type list or unhashable list is used by List implementation in many programming languages. For Example-

Python’s index implementation makes use of unhashable lists upon its implementation to represent the index inside an array as separate objects; this means that one could iterate over a list of objects without knowing anything about how they were stored (other than their index). 

It also allows one to work with individual objects as opposed to entire lists (because rather than iterating through an entire object you can directly access its members). 

5. There is one piece of code that made unhashable type list famous

This list was first implemented by John Carmack to represent level maps for the first “Doom” game, which had an ability to create procedural levels based on input text files; although, this would later be replaced with a simpler approach (which wouldn’t use this technique) by id Software.

Unhashable type lists can be implemented using any kind of data structure, but the hash function should still be applied to the data structure.

The use of an unhashable type list is widely used in game development. 

It’s because it’s an easy way to create random maps without changing original game data files. Nowadays, it might be replaced by a Terrain system. 

6. Unhashable type list is used in Java 8- Streams

Unhashable type lists are used to represent java stream elements. For example, if you have a Map and you want to stream all its keys, you can do it using Stream.of(). This uses an Unhashable type list of the key values. 

7. Unhashable type list is used in functional programming languages like Haskell

The object implementing the Functor interface may be defined as an array, but not as a hash table since these are not referentially transparent. 

The read operation uses lazy evaluation, making it unsuitable for implementations that need all elements to be available when the array holding them is created. 

If you want a hash table for this use case, define the Hashable datatype as a list of elements, and then implement read as follows:

The only way to determine whether two elements are equal is by examining their address in memory. 

Therefore, the program cannot determine if all elements have been mapped out, and it cannot avoid generating collisions.

Previous articleBest of blogging cameras
Next articleTop minds – Reddit
There are many labels that could be given to describe me, but one thing’s for certain: I am an entrepreneur with passion. Whether it's building websites and social media campaigns for new businesses or traveling the world on business trips - being entrepreneurs means constantly looking at yourself in a different light so as not get bored of your own success!


Please enter your comment!
Please enter your name here