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.