Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
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

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Peter Otten
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

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
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']] = {

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Danny Yoo
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

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
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

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Danny Yoo
>{'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

[Tutor] Question on List of Dict

2014-09-18 Thread Sunil Tech
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