Thank you Peter Otten,
actually i should study about the collections and defaultdict like how and
where these can be used and its advantage.
On Fri, Sep 19, 2014 at 5:59 PM, Peter Otten <__pete...@web.de> wrote:
> Sunil Tech wrote:
>
> > Danny i did it like this
> >
> > result_dict = {}
> > fo
Sunil Tech wrote:
> Danny i did it like this
>
> result_dict = {}
> for i in tes:
> if i['a'] in result_dict:
> temp = result_dict[i['a']]
> temp['b'].append(i['b'])
> temp['c'].append(i['c'])
> temp['a'] = i['a']
> result_dict[i['a']] = temp
> else
Danny i did it like this
result_dict = {}
for i in tes:
if i['a'] in result_dict:
temp = result_dict[i['a']]
temp['b'].append(i['b'])
temp['c'].append(i['c'])
temp['a'] = i['a']
result_dict[i['a']] = temp
else:
result_dict[i['a']] = {
On Sep 19, 2014 12:28 AM, "Danny Yoo" wrote:
>
>
> >{'a': 2, 'b': 'another', 'c': 754},
> >{'a': 2, 'b': 'word', 'c': 745}
> >
>
> > if the value of the 'a' is same, then all those other values of the
dict should be merged/clubbed.
>
> Can you write a function that takes two of the
Danny,
i wrote a method called *merge *below
can you be little clear with an example
I wrote something like this
ids = []
for i in tes:
if i['a'] not in ids:
ids.append(i['a'])
print ids
def merge(ids, tes):
for jj in ids:
txt = ''
for i in tes:
i
>{'a': 2, 'b': 'another', 'c': 754},
>{'a': 2, 'b': 'word', 'c': 745}
>
> if the value of the 'a' is same, then all those other values of the dict
should be merged/clubbed.
Can you write a function that takes two of these and merges them? Assume
that they have the same 'a'. Can
Hi all,
tes = [{'a': 1, 'b': 'this', 'c': 221},
{'a': 2, 'b': 'this', 'c': 215},
{'a': 1, 'b': 'is', 'c': 875},
{'a': 1, 'b': 'sentence', 'c': 874},
{'a': 2, 'b': 'another', 'c': 754},
{'a': 2, 'b': 'word', 'c': 745}]
The above one is the result form the DB. I