How to assign value to element in nested dictionary in Python
0
0
Entering edit mode
16 months ago
Paula ▴ 60

Hi all!

I have a question. I have the following nested dictionary:

{'Cluster 0': {'samples': {'SOL 1_3'}}}

And I would like to modify the dictionary to include the abundance per sample:

{'Cluster 0': {'samples': {'SOL 1_3':7}}}

I tried this command:

dct_cluster_sol[current_cluster]['samples']['SOL_1_3'] = 7

And it gives this error:

 dct_cluster_sol[current_cluster]['samples']['SOL_1_3'] = 7
 TypeError: 'set' object does not support item assignment

Do you know how to solve it?

Thank you!

dictionary python • 684 views
ADD COMMENT
1
Entering edit mode

{'Cluster 0': {'samples': {'SOL 1_3'}}} has the mapping {str -> { str -> set }}. You probably only need {'Cluster 0': {'samples': dict()}}

ADD REPLY
0
Entering edit mode

Thanks! It worked!

ADD REPLY

Login before adding your answer.

Traffic: 2599 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6