-2

i have a dictionary : table name :

     {
        column 1:
            {
            value 1 : [data,data,data]
            }
        column 2:
            {
            value 1 : [data,data,data]
            }
     }

now i want to add value 2 inside each column and those values are stored inside a list

list1 = [{value2 : [data,data]}, {value2 : [data,data]}

table name :

     {
        column 1:
            {
               value 1 : [data,data,data]
               value 2 : [data,data]
            }
        column 2:
            {
               value 1 : [data,data,data]
               value 2 : [data,data]
            }
      }
Shubhitgarg
  • 588
  • 6
  • 20
MaTHwoG
  • 1,911
  • 2
  • 7
  • 11
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [how to give a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it much easier for others to help you. – Aditi Feb 23 '18 at 04:33
  • 1
    You have to first try, and then come here to ask questions if you are struck.Do not expect complete solutions without any attempt. – Keshav Pradeep Ramanath Feb 23 '18 at 05:01

2 Answers2

1

Its not clear, I hope you are asking adding key and list of value into dictionary inside a dictionary

You can do that like this:

tablename[column 1][newKey] = [list of values]

example

tablename= {

    'col1' : {
        'val1':[1,2,44,5],
        },
    'col2' : {
        'val1' : [2,3,47,70]
    }

}

Output will be

{'col1': {'val1': [1, 2, 44, 5]}, 'col2': {'val1': [2, 3, 47, 70]}}

Adding new key:

tablename['col1']['val2'] = [1,2]
tablename['col2']['val2'] = [3,4]

This output will be

{'col1': {'val1': [1, 2, 44, 5], 'val2': [1, 2]}, 'col2': {'val1': [2, 3, 47, 70], 'val2': [3, 4]}}

I hope this will helps.

Sarath_Mj
  • 323
  • 1
  • 2
  • 14
1

You can try this as well

tablename= {

    'col1' : {
        'val1':[1,2,44,5],
        },
    'col2' : {
        'val1' : [2,3,47,70]
    }

}

then add new key like this

val2 = [1,2,3,4]
tablename['col1']['val2'] = val2 
tablename['col2']['val2'] = val2 
predsar
  • 66
  • 2