Is there a better way to do this snippet?

python w.g.sneddon at gmail.com
Tue Apr 3 10:36:13 EDT 2012


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.
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)):
... 		g23tag[key].append(value)
... 	else:
... 		g23tag[key] = [value]



More information about the Python-list mailing list