 <p>I have a more compact method.</p> <p>I think it's more readable and easy to understand. You can refer as below:</p> <p>This is your var I delcare <code>response</code>:</p> <pre><code>response = [ {'country': 'KR', 'values': ['Server1']}, {'country': 'IE', 'values': ['Server1', 'Server3', 'Server2']}, {'country': 'IE', 'values': ['Server1', 'Server3']}, {'country': 'DE', 'values': ['Server1']}, {'country': 'DE', 'values': ['Server2']}, ] </code></pre> <p>Let's merge the values.</p> <pre><code>new_res = {} for e in response: if e['country'] not in new_res: new_res[e['country']] = e['values'] else: new_res[e['country']].extend(e['values']) </code></pre> <p>You can print <code>new_res</code> if you want to know its content. It's like as below:</p> <pre><code>{ 'KR': ['Server1'], 'DE': ['Server1', 'Server2'], 'IE': ['Server1', 'Server3', 'Server2', 'Server1', 'Server3'] } </code></pre> <p>Invoking <code>collections</code> module collects elements:</p> <pre><code>from collections import Counter new_list = [] for country, values in new_res.items(): # elements are stored as dictionary keys and their counts are stored as dictionary values merge_values = Counter(values) # calculate percentage new_values = [] total = sum(merge_values.values()) for server_name, num in merge_values.items(): #ex: Server1-40.0 new_values.append("{0}-{1:.1f}".format(server_name, num*100/total)) percent = merge_values["Server1"]*1.0*100/total new_list.append({"country": country, "percent": percent, "values": new_values}) </code></pre> <p>You can print <code>new_list</code> when finishing calculating result:</p> <pre><code>[{'country': 'KR', 'percent': 100.0, 'values': ['Server1-100.0']}, {'country': 'DE', 'percent': 50.0, 'values': ['Server1-50.0', 'Server2-50.0']}, {'country': 'IE', 'percent': 40.0, 'values': ['Server1-40.0', 'Server2-20.0', 'Server3-40.0']}] </code></pre> <p>So you can get answer you want.</p>