Re: Is there a better way to do this snippet?

2012-04-03 Thread nn
On Apr 3, 12:26 pm, Alain Ketterlin wrote: > nn writes: > >> > for item in tag23gr: > >> > ...        value, key = tuple(item) > >> > ...        if(g23tag.get(key)): > >> > ...                g23tag[key].append(value) > >> > ...        else: > >> > ...                g23tag[key] = [value] > > >>

Re: Is there a better way to do this snippet?

2012-04-03 Thread Alain Ketterlin
nn writes: >> > for item in tag23gr: >> > ...        value, key = tuple(item) >> > ...        if(g23tag.get(key)): >> > ...                g23tag[key].append(value) >> > ...        else: >> > ...                g23tag[key] = [value] >> >> for item in tag23gr: >>     g23tag.setdefault(item[0],[]).

Re: Is there a better way to do this snippet?

2012-04-03 Thread nn
On Apr 3, 11:02 am, Alain Ketterlin wrote: > python writes: > > tag23gr is a list of lists each with two items. > > g23tag is an empty dictionary when I run the for loop below. > > When is is complete each key is a graphic name who's values are a list > > of tags. > > > for item in tag23gr: > > .

Re: Is there a better way to do this snippet?

2012-04-03 Thread Peter Otten
python wrote: > I played around with a few things and this works but was wondering if > there was a better way to do this. > My first thought was list comprehension but could not get a figure out > the syntax. > > tag23gr is a list of lists each with two items. > g23tag is an empty dictionary whe

Re: Is there a better way to do this snippet?

2012-04-03 Thread Chris Angelico
On Wed, Apr 4, 2012 at 12:36 AM, python wrote: > for item in tag23gr: > ...     value, key = tuple(item) > ...     if(g23tag.get(key)): > ...             g23tag[key].append(value) > ...     else: > ...             g23tag[key] = [value] Simple enhancement: Use setdefault. Instead of the if, just u

Re: Is there a better way to do this snippet?

2012-04-03 Thread Alain Ketterlin
python writes: > tag23gr is a list of lists each with two items. > g23tag is an empty dictionary when I run the for loop below. > When is is complete each key is a graphic name who's values are a list > of tags. > > for item in tag23gr: > ... value, key = tuple(item) > ... if(g23tag.get(key))

Is there a better way to do this snippet?

2012-04-03 Thread python
I played around with a few things and this works but was wondering if there was a better way to do this. My first thought was list comprehension but could not get a figure out the syntax. tag23gr is a list of lists each with two items. g23tag is an empty dictionary when I run the for loop below. W