led4966
led4966

Reputation: 49

How to add new key value pair to a list of dictionaries?

I am initializing a list of dictionaries with:

sequences = [dict() for x in range(83)]

I want to be able to add key : value pairs to a certain dictionary. For example, I want to add the key value pair primer 1 : primer 2 to the first slot in the list.

sequences[0].update({ primer1 : primer2 })

This gives me the error TypeError: unhashable type: 'list'. How am I able to access a certain dictionary within the list to add a key value pair?

Upvotes: 3

Views: 1122

Answers (1)

wim
wim

Reputation: 362547

This error message suggests that the key primer1 is a list (or contains a list).

What you're attempting will not be possible, because dict keys must be hashable in Python. Instead, you may use a hashable sequence type for the key primer1, such as a tuple.

Upvotes: 3

Related Questions