Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add key,value pair to dictionary? [duplicate]

Tags:

python

How to add key,value pair to dictionary?.Below i have mentioned following format?

{'1_somemessage': [[3L,                     1L,                     u'AAA',                     1689544L,                     datetime.datetime(2010, 9, 21, 22, 30),                     u'gffggf'],                    [3L,                     1L,                     u'BBB',                     1689544L,                     datetime.datetime(2010, 9, 21, 20, 30),                     u'ffgffgfg'],                    [3L,                     1L,                     u'CCC',                     1689544L,                     datetime.datetime(2010, 9, 21, 22, 30),                     u'hjhjhjhj'],                    [3L,                     1L,                     u'DDD',                     1689544L,                     datetime.datetime(2010, 9, 21, 21, 45),                     u'jhhjjh']],  '2_somemessage': [[4L,                     1L,                     u'AAA',                     1689544L,                     datetime.datetime(2010, 9, 21, 22, 30),                     u'gffggf'],                    [4L,                     1L,                     u'BBB',                     1689544L,                     datetime.datetime(2010, 9, 21, 20, 30),                     u'ffgffgfg'],                    [4L,                     1L,                     u'CCC',                     1689544L,                     datetime.datetime(2010, 9, 21, 22, 30),                     u'hjhjhjhj'],                    [4L,                     1L,                     u'DDD',                     1689544L,                     datetime.datetime(2010, 9, 21, 21, 45),                     u'jhhjjh']]} 
like image 971
Krishnasamy Avatar asked Sep 23 '10 07:09

Krishnasamy


People also ask

Can key value pair have duplicate keys?

You can use List<KeyValuePair<string,int>> . This will store a list of KeyValuePair 's that can be duplicate.

Can we add duplicate values in dictionary?

[C#] Dictionary with duplicate keys The Key value of a Dictionary is unique and doesn't let you add a duplicate key entry.

Can we add duplicate values in dictionary C#?

In Dictionary, key must be unique. Duplicate keys are not allowed if you try to use duplicate key then compiler will throw an exception. In Dictionary, you can only store same types of elements.


1 Answers

Add a key, value pair to dictionary

aDict = {} aDict[key] = value 

What do you mean by dynamic addition.

like image 107
pyfunc Avatar answered Sep 20 '22 16:09

pyfunc