Skip to content

Instantly share code, notes, and snippets.

@nosahama
Last active March 1, 2018 18:13
Show Gist options
  • Save nosahama/eb2a1b40d36e0d2568cc6960fde44c2d to your computer and use it in GitHub Desktop.
Save nosahama/eb2a1b40d36e0d2568cc6960fde44c2d to your computer and use it in GitHub Desktop.
Cooccurrence Question
## This is the text editor interface.
## Anything you type or change here will be seen by the other person in real time.
import itertools
from collections import defaultdict
class Cooccurrence:
def __init__(self):
self.__counts = defaultdict(int)
def append(self, line):
s = line.split()
s.sort()
for i in itertools.combinations(s, 2):
print(i, line)
self.__counts[i] += 1
def get(self, a, b):
params = [a, b]
params.sort()
return self.__counts[(params[0], params[1])]
# alice bob
# bob claire dan alice
c = Cooccurrence()
c.append('alice bob')
c.append('bob claire dan alice')
c.append('ben claire dele alice')
c.append('ben john dele amaka')
c.append('ben dele alice bob')
c.get('alice', 'bob')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment