Many times when I am writing some program in python, I notice that I
could transform my list into set, then use the set methods like union,
intersection, set equality etc. , and it will solve my problem easily.
But then I realize that if I transform my list into set, it will
remove duplicates
For example, I was writing a program to detect whether two strings are
anagrams of each other. I had to write it like this:
def isAnagram(w1, w2):
w2=list(w2)
for c in w1:
if c not in w2:
return False
else:
w2.remove(c)
return True
But if there was a data
On Fri, May 20, 2011 at 9:37 PM, ErichCart ErichCart
erichc...@gmail.com wrote:
For example, I was writing a program to detect whether two strings are
anagrams of each other. I had to write it like this:
def isAnagram(w1, w2):
w2=list(w2)
for c in w1:
if c not in w2:
return False
I see! How could I overlook sorting ))
It seems that collections.Counter is what I was talking about. It
seems to support all the set operations.
Also I realized that the data structure which i was describing is
called miltiset, and collections.Counter is python implementation of
multiset.
--