Python: merge a value of key if it exists more than one times within a same dictionary












-3















I'm working in python and I'm trying to get values of the key if it exists more than one times within a dictionary. I have a tuple of multiple dictionaries as follows;



({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})



I want result like this;



{'ios': 1.0, 'concept': 0.449, 'sql_server': 0.766, '2012': 0.369, '.net':[0.21,1.0,0.267,0.203,0.254], 'microsoft_kinect_sdk_1.8': 1.0, 'sql': 0.268, 'css': 0.223, 'ado.net': 0.447, 'asp.net':[0.234,0.494.0.254], 'oriented': 0.41, 'c++': 0.346, 'html': 0.228, 'j2ee': 1.0, 'object-oriented': 0.376, 'jquery': 0.201, 'vb': 0.49, 'rails': 0.424, 'c#': 0.214, 'ruby': 0.432, 'android': 1.0, 'java_ee': 0.38, 'sql_server': 0.289, 'java': 0.207, 'object': 0.407, '2008': 0.325, 'asp': 0.513, 'fphp': 0.654, 'javascript': 0.2, 'liferay': 0.86, 'prototype': 0.481}



thank you in advance.










share|improve this question























  • You mean you want to merge it if it shows up more than one time in different dictonaries?

    – Miguel
    Jan 19 at 18:23











  • Can you show your attempt at solving this problem, please?

    – Austin
    Jan 19 at 18:23
















-3















I'm working in python and I'm trying to get values of the key if it exists more than one times within a dictionary. I have a tuple of multiple dictionaries as follows;



({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})



I want result like this;



{'ios': 1.0, 'concept': 0.449, 'sql_server': 0.766, '2012': 0.369, '.net':[0.21,1.0,0.267,0.203,0.254], 'microsoft_kinect_sdk_1.8': 1.0, 'sql': 0.268, 'css': 0.223, 'ado.net': 0.447, 'asp.net':[0.234,0.494.0.254], 'oriented': 0.41, 'c++': 0.346, 'html': 0.228, 'j2ee': 1.0, 'object-oriented': 0.376, 'jquery': 0.201, 'vb': 0.49, 'rails': 0.424, 'c#': 0.214, 'ruby': 0.432, 'android': 1.0, 'java_ee': 0.38, 'sql_server': 0.289, 'java': 0.207, 'object': 0.407, '2008': 0.325, 'asp': 0.513, 'fphp': 0.654, 'javascript': 0.2, 'liferay': 0.86, 'prototype': 0.481}



thank you in advance.










share|improve this question























  • You mean you want to merge it if it shows up more than one time in different dictonaries?

    – Miguel
    Jan 19 at 18:23











  • Can you show your attempt at solving this problem, please?

    – Austin
    Jan 19 at 18:23














-3












-3








-3








I'm working in python and I'm trying to get values of the key if it exists more than one times within a dictionary. I have a tuple of multiple dictionaries as follows;



({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})



I want result like this;



{'ios': 1.0, 'concept': 0.449, 'sql_server': 0.766, '2012': 0.369, '.net':[0.21,1.0,0.267,0.203,0.254], 'microsoft_kinect_sdk_1.8': 1.0, 'sql': 0.268, 'css': 0.223, 'ado.net': 0.447, 'asp.net':[0.234,0.494.0.254], 'oriented': 0.41, 'c++': 0.346, 'html': 0.228, 'j2ee': 1.0, 'object-oriented': 0.376, 'jquery': 0.201, 'vb': 0.49, 'rails': 0.424, 'c#': 0.214, 'ruby': 0.432, 'android': 1.0, 'java_ee': 0.38, 'sql_server': 0.289, 'java': 0.207, 'object': 0.407, '2008': 0.325, 'asp': 0.513, 'fphp': 0.654, 'javascript': 0.2, 'liferay': 0.86, 'prototype': 0.481}



thank you in advance.










share|improve this question














I'm working in python and I'm trying to get values of the key if it exists more than one times within a dictionary. I have a tuple of multiple dictionaries as follows;



({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})



I want result like this;



{'ios': 1.0, 'concept': 0.449, 'sql_server': 0.766, '2012': 0.369, '.net':[0.21,1.0,0.267,0.203,0.254], 'microsoft_kinect_sdk_1.8': 1.0, 'sql': 0.268, 'css': 0.223, 'ado.net': 0.447, 'asp.net':[0.234,0.494.0.254], 'oriented': 0.41, 'c++': 0.346, 'html': 0.228, 'j2ee': 1.0, 'object-oriented': 0.376, 'jquery': 0.201, 'vb': 0.49, 'rails': 0.424, 'c#': 0.214, 'ruby': 0.432, 'android': 1.0, 'java_ee': 0.38, 'sql_server': 0.289, 'java': 0.207, 'object': 0.407, '2008': 0.325, 'asp': 0.513, 'fphp': 0.654, 'javascript': 0.2, 'liferay': 0.86, 'prototype': 0.481}



thank you in advance.







python list key






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 19 at 18:21









Juhi dhameliaJuhi dhamelia

32




32













  • You mean you want to merge it if it shows up more than one time in different dictonaries?

    – Miguel
    Jan 19 at 18:23











  • Can you show your attempt at solving this problem, please?

    – Austin
    Jan 19 at 18:23



















  • You mean you want to merge it if it shows up more than one time in different dictonaries?

    – Miguel
    Jan 19 at 18:23











  • Can you show your attempt at solving this problem, please?

    – Austin
    Jan 19 at 18:23

















You mean you want to merge it if it shows up more than one time in different dictonaries?

– Miguel
Jan 19 at 18:23





You mean you want to merge it if it shows up more than one time in different dictonaries?

– Miguel
Jan 19 at 18:23













Can you show your attempt at solving this problem, please?

– Austin
Jan 19 at 18:23





Can you show your attempt at solving this problem, please?

– Austin
Jan 19 at 18:23












1 Answer
1






active

oldest

votes


















0














I guess the below code will help you:



aa = ({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})

bb = {}
for i in aa:
for k, v in i.items():
bb.setdefault(k, ).append(v)

print (bb)


#output
{'object': [0.407], '2008': [0.325], 'concept': [0.449], 'c#': [0.222, 0.468, 0.282, 0.214], '.net': [0.21, 1.0, 0.267, 0.203], 'oriented': [0.41], '2012': [0.369], 'asp.net': [0.234, 0.494, 0.254], 'sql_server': [0.274, 0.289], 'microsoft_kinect_sdk_1.8': [1.0], 'sql': [0.268], 'ado.net': [0.447], 'c++': [0.346], 'java': [0.248, 0.227, 0.207], 'sql_serverâ': [0.766], 'asp': [0.513], 'jquery': [0.201], 'vb': [0.49], 'prototype': [0.481], 'css': [0.199, 0.223], 'javascript': [0.357, 0.163, 1.0, 0.2], 'html': [0.204, 0.228], 'object-oriented': [0.376], 'android': [0.216, 1.0], 'java_ee': [0.38], 'liferay': [0.86], 'j2ee': [1.0], 'ios': [1.0], 'ruby': [0.432], 'rails': [0.424], 'fphp': [0.654]}


If you don't want list object for the single value element e.g. object: [0.407] then you can convert it into a string in further processing.






share|improve this answer
























  • Thank you, this code gives the exact output as I wanted.

    – Juhi dhamelia
    Jan 21 at 16:41











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270074%2fpython-merge-a-value-of-key-if-it-exists-more-than-one-times-within-a-same-dict%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I guess the below code will help you:



aa = ({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})

bb = {}
for i in aa:
for k, v in i.items():
bb.setdefault(k, ).append(v)

print (bb)


#output
{'object': [0.407], '2008': [0.325], 'concept': [0.449], 'c#': [0.222, 0.468, 0.282, 0.214], '.net': [0.21, 1.0, 0.267, 0.203], 'oriented': [0.41], '2012': [0.369], 'asp.net': [0.234, 0.494, 0.254], 'sql_server': [0.274, 0.289], 'microsoft_kinect_sdk_1.8': [1.0], 'sql': [0.268], 'ado.net': [0.447], 'c++': [0.346], 'java': [0.248, 0.227, 0.207], 'sql_serverâ': [0.766], 'asp': [0.513], 'jquery': [0.201], 'vb': [0.49], 'prototype': [0.481], 'css': [0.199, 0.223], 'javascript': [0.357, 0.163, 1.0, 0.2], 'html': [0.204, 0.228], 'object-oriented': [0.376], 'android': [0.216, 1.0], 'java_ee': [0.38], 'liferay': [0.86], 'j2ee': [1.0], 'ios': [1.0], 'ruby': [0.432], 'rails': [0.424], 'fphp': [0.654]}


If you don't want list object for the single value element e.g. object: [0.407] then you can convert it into a string in further processing.






share|improve this answer
























  • Thank you, this code gives the exact output as I wanted.

    – Juhi dhamelia
    Jan 21 at 16:41
















0














I guess the below code will help you:



aa = ({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})

bb = {}
for i in aa:
for k, v in i.items():
bb.setdefault(k, ).append(v)

print (bb)


#output
{'object': [0.407], '2008': [0.325], 'concept': [0.449], 'c#': [0.222, 0.468, 0.282, 0.214], '.net': [0.21, 1.0, 0.267, 0.203], 'oriented': [0.41], '2012': [0.369], 'asp.net': [0.234, 0.494, 0.254], 'sql_server': [0.274, 0.289], 'microsoft_kinect_sdk_1.8': [1.0], 'sql': [0.268], 'ado.net': [0.447], 'c++': [0.346], 'java': [0.248, 0.227, 0.207], 'sql_serverâ': [0.766], 'asp': [0.513], 'jquery': [0.201], 'vb': [0.49], 'prototype': [0.481], 'css': [0.199, 0.223], 'javascript': [0.357, 0.163, 1.0, 0.2], 'html': [0.204, 0.228], 'object-oriented': [0.376], 'android': [0.216, 1.0], 'java_ee': [0.38], 'liferay': [0.86], 'j2ee': [1.0], 'ios': [1.0], 'ruby': [0.432], 'rails': [0.424], 'fphp': [0.654]}


If you don't want list object for the single value element e.g. object: [0.407] then you can convert it into a string in further processing.






share|improve this answer
























  • Thank you, this code gives the exact output as I wanted.

    – Juhi dhamelia
    Jan 21 at 16:41














0












0








0







I guess the below code will help you:



aa = ({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})

bb = {}
for i in aa:
for k, v in i.items():
bb.setdefault(k, ).append(v)

print (bb)


#output
{'object': [0.407], '2008': [0.325], 'concept': [0.449], 'c#': [0.222, 0.468, 0.282, 0.214], '.net': [0.21, 1.0, 0.267, 0.203], 'oriented': [0.41], '2012': [0.369], 'asp.net': [0.234, 0.494, 0.254], 'sql_server': [0.274, 0.289], 'microsoft_kinect_sdk_1.8': [1.0], 'sql': [0.268], 'ado.net': [0.447], 'c++': [0.346], 'java': [0.248, 0.227, 0.207], 'sql_serverâ': [0.766], 'asp': [0.513], 'jquery': [0.201], 'vb': [0.49], 'prototype': [0.481], 'css': [0.199, 0.223], 'javascript': [0.357, 0.163, 1.0, 0.2], 'html': [0.204, 0.228], 'object-oriented': [0.376], 'android': [0.216, 1.0], 'java_ee': [0.38], 'liferay': [0.86], 'j2ee': [1.0], 'ios': [1.0], 'ruby': [0.432], 'rails': [0.424], 'fphp': [0.654]}


If you don't want list object for the single value element e.g. object: [0.407] then you can convert it into a string in further processing.






share|improve this answer













I guess the below code will help you:



aa = ({'object': 0.407, '2008': 0.325, 'concept': 0.449, 'c#': 0.222, '.net': 0.21, 'oriented': 0.41, '2012': 0.369, 'asp.net': 0.234, 'sql_server': 0.274}, {'microsoft_kinect_sdk_1.8': 1.0}, {'sql': 0.268, 'ado.net': 0.447, 'c#': 0.468, 'asp.net': 0.494, 'c++': 0.346, 'sql_server': 0.289, 'java': 0.248}, {'.net': 1.0}, {'sql_serverâ': 0.766, 'c#': 0.282, 'asp': 0.513, '.net': 0.267}, {'jquery': 0.201, 'vb': 0.49, 'prototype': 0.481, 'c#': 0.214, '.net': 0.203, 'css': 0.199, 'javascript': 0.357, 'html': 0.204, 'object-oriented': 0.376, 'java': 0.227}, {'javascript': 0.163, 'android': 0.216, 'java_ee': 0.38, 'liferay': 0.86, 'java': 0.207}, {'j2ee': 1.0}, {'javascript': 1.0}, {'android': 1.0}, {'ios': 1.0}, {'ruby': 0.432, 'rails': 0.424, 'asp.net': 0.254, 'css': 0.223, 'fphp': 0.654, 'javascript': 0.2, 'html': 0.228})

bb = {}
for i in aa:
for k, v in i.items():
bb.setdefault(k, ).append(v)

print (bb)


#output
{'object': [0.407], '2008': [0.325], 'concept': [0.449], 'c#': [0.222, 0.468, 0.282, 0.214], '.net': [0.21, 1.0, 0.267, 0.203], 'oriented': [0.41], '2012': [0.369], 'asp.net': [0.234, 0.494, 0.254], 'sql_server': [0.274, 0.289], 'microsoft_kinect_sdk_1.8': [1.0], 'sql': [0.268], 'ado.net': [0.447], 'c++': [0.346], 'java': [0.248, 0.227, 0.207], 'sql_serverâ': [0.766], 'asp': [0.513], 'jquery': [0.201], 'vb': [0.49], 'prototype': [0.481], 'css': [0.199, 0.223], 'javascript': [0.357, 0.163, 1.0, 0.2], 'html': [0.204, 0.228], 'object-oriented': [0.376], 'android': [0.216, 1.0], 'java_ee': [0.38], 'liferay': [0.86], 'j2ee': [1.0], 'ios': [1.0], 'ruby': [0.432], 'rails': [0.424], 'fphp': [0.654]}


If you don't want list object for the single value element e.g. object: [0.407] then you can convert it into a string in further processing.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 21 at 12:38









Akash SwainAkash Swain

1995




1995













  • Thank you, this code gives the exact output as I wanted.

    – Juhi dhamelia
    Jan 21 at 16:41



















  • Thank you, this code gives the exact output as I wanted.

    – Juhi dhamelia
    Jan 21 at 16:41

















Thank you, this code gives the exact output as I wanted.

– Juhi dhamelia
Jan 21 at 16:41





Thank you, this code gives the exact output as I wanted.

– Juhi dhamelia
Jan 21 at 16:41


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270074%2fpython-merge-a-value-of-key-if-it-exists-more-than-one-times-within-a-same-dict%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Callistus III

Ostreoida

Plistias Cous