Imagine you have a list where you then need to take a set portion of it as a batch.
Below gits
shows how to use a while
loop for this to creat batches.
By converting two lists into sets and then comparing them, we can get a list of items that weren't batch first time around. This works for a regular list.
However for a list of json
objects, as above, we can't use set
. If used as a regular list, it throws below error.
TypeError: unhashable type: 'dict'
and the reason is, as nicely described here
You're trying to use a dict as a key to another
dict
or in aset
. That does not work because the keys have to be hashable. As a general rule, only immutable objects (strings, integers, floats, frozensets, tuples of immutables) are hashable (though exceptions are possible).
Therefore, to do the same, we could take advantage of slice
as shown in the second code gist.