Skip to content

Instantly share code, notes, and snippets.

@zonuexe
Created September 30, 2011 09:33
Show Gist options
  • Save zonuexe/1253253 to your computer and use it in GitHub Desktop.
Save zonuexe/1253253 to your computer and use it in GitHub Desktop.
Pythonで多重集合?
#!/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