Skip to content

Instantly share code, notes, and snippets.

@nozma
Last active August 16, 2017 14:36
Show Gist options
  • Select an option

  • Save nozma/baf2e219916aa1c231c0ef5341716f3b to your computer and use it in GitHub Desktop.

Select an option

Save nozma/baf2e219916aa1c231c0ef5341716f3b to your computer and use it in GitHub Desktop.
# coding: utf-8
# 2つのバイグラムの和集合、積集合、差集合
def bi_gram(s):
result = []
for i in range(0, len(s)-1):
result.append(s[i:i+2])
return result
s1 = 'paraparaparadise'
s2 = 'paragraph'
X = set(bi_gram(s1))
Y = set(bi_gram(s2))
print("X = ", X)
print("Y = ", Y)
print("union: ", X | Y) # union
print("intersection: ", X & Y) # intersection
print("difference: ", X - Y) # difference
if "se" in X:
print("X contain 'se'.")
else:
print("X doesn't contain 'se'.")
if "se" in Y:
print("Y contain 'se'.")
else:
print("Y doesn't contain 'se'.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment