Use defaultdict type where possible for minor performance gain and source code simplification

svn: r14011
This commit is contained in:
Gerald Britton
2010-01-09 19:54:32 +00:00
parent 4c7365dbcf
commit 2b12f3df07
7 changed files with 32 additions and 62 deletions

View File

@@ -35,6 +35,7 @@ import os
from gettext import gettext as _
from cStringIO import StringIO
from collections import defaultdict
#-------------------------------------------------------------------------
#
@@ -1489,22 +1490,19 @@ class ViewManager(CLIManager):
menu = gtk.Menu()
menu.show()
hash_data = {}
hash_data = defaultdict(list)
for pdata in item_list:
if not pdata.supported:
category = _UNSUPPORTED
else:
category = categories[pdata.category]
if category in hash_data:
hash_data[category].append(pdata)
else:
hash_data[category] = [pdata]
hash_data[category].append(pdata)
# Sort categories, skipping the unsupported
catlist = [item for item in hash_data
if item != _UNSUPPORTED]
catlist.sort()
catlist = sorted(item for item in hash_data
if item != _UNSUPPORTED)
for key in catlist:
new_key = key.replace(' ', '-')
ofile.write('<menu action="%s">' % new_key)