[Yum-devel] [PATCH] make sure when we return items we sort the counts of things matched from the tagsdb into the rest of the matches. FIXME added to get rid of the silly sorting list as it appears to only want to make me cry
Ville Skyttä
ville.skytta at iki.fi
Fri Mar 12 17:35:06 UTC 2010
On Friday 12 March 2010, Seth Vidal wrote:
> http://fpaste.org/aOLJ/raw/
>
> this script measures 3 mechanism for making a dict like we're describing.
>
> run it yourself - but dict3 is using:
>
> if not item in dict:
> dict[item] = []
>
>
> dict1 is one setdefault
> dict2 is a pretty bizarre setdefault
>
> long story short - dict3 is twice as fast as dict1 and a bazillion times
> faster than dict2.
BTW with Python >= 2.5 collections.defaultdict(list) would be one more
alternative, even faster and in my opinion also the most readable.
import collections
def dict_4():
d = collections.defaultdict(list)
for y in xrange(0, 100000):
word2 = WORDS[y%3]
d[word2].append(y)
But I suppose yum is supposed to run with Python 2.4 still so this is not an
option, at least yet. And they behave differently from normal dicts so they
need to be used carefully and can't be just blindly used as a replacement,
especially as API values.
More information about the Yum-devel
mailing list