Created
September 30, 2011 09:33
-
-
Save zonuexe/1253253 to your computer and use it in GitHub Desktop.
Pythonで多重集合?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#こんなので良いの? もっと良い組込みライブラリとかないの? | |
class Multiset(object): | |
def __init__(self): | |
self._collection = {} | |
def add(self, value): | |
if value in self._collection: | |
self._collection[value] += 1 | |
else: | |
self._collection[value] = 1 | |
def collection(self): | |
return self._collection | |
a = Multiset() | |
a.add("a") | |
a.add("a") | |
a.add("a") | |
a.add("b") | |
a.add("b") | |
a.add("b") | |
a.add("b") | |
a.add("c") | |
print a.collection() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment