On Mon, Feb 28, 2011 at 10:50 AM, Bináris <wikiposta(a)gmail.com> wrote:
2011/2/28 Morten Wang <nettrom(a)gmail.com>
seenCategories = set();
# then in my loop:
if not cat.title() in seenCategories:
seenCategories.add(cat.title());
# do something with this category
I think the "if" line is not necessary here because of definition of sets.
Just add.
The if-line is there to make sure that the category is not
used/traversed more than once, which then makes sure that loops are
never a problem, sorry if that was not obvious from my code snippet.
So the code translates to "if this category has not been seen before,
add the category title to the set of seen categories, and continue
processing this category".
You could of course also do the opposite, skip the category if it's
already in the set.
Cheers,
Morten