I see examples on Hugging face where they are zipping dictionaries with list (one such example below):
batch = {'input_ids': [[1,2,3], [4,5,6]], 'attention_mask': [[1,1,1], [0,0,0]], 'labels': [[10, 11, 12], [13, 14, 15]]}
def insert_random_mask(batch):
features = [dict(zip(batch, t)) for t in zip(*batch.values())]
return features
print(insert_random_mask(batch)
>>> [{'input_ids': [1, 2, 3], 'attention_mask': [1, 1, 1], 'labels': [10, 11, 12]}, {'input_ids': [4, 5, 6], 'attention_mask': [0, 0, 0], 'labels': [13, 14, 15]}]
I also see SO posts on the same too: Zipping a Python Dictionary and List together
But dictionaries do not provide ordering. How is it ok to zip an (unordered) dictionary with an ordered list?
Edit: it is not about iterability of dict, it is more about mapping the right keys with right values. In the example about if ordering is not guaranteed, how can you be sure that you are mapping the right values with the keys