Aizayousaf
Aizayousaf

Reputation: 49

issue with Storing dictionary with key and multi values for key in python

I have a loop on utterances(list of statements)

predicted_utt_label=defaultdict(list)
for utt in test_utterances:
         #here some code to detect label for each statement

Now I want to add utterance and its label in a dictionary and write the code here:

 predicted_utt_label[utt]=DA

But there is a problem with the statement like 'I don't know' and 'I don't know' with different labels like 'sd' and 'qy'. As both statements have different labels then how I can store them as statement key of dictionary and labels as multi value of that key? Because dictionary always have unique keys.

Upvotes: 1

Views: 40

Answers (1)

user10993451
user10993451

Reputation:

Using a list as a key to each value will allow you to store multiple values to each key. Use a for loop to find the key needed and use another loop or even just a list comprehension to add the new value to this list of values. Let us know if this is of any help

Upvotes: 1

Related Questions