Last active
August 16, 2017 14:36
-
-
Save nozma/baf2e219916aa1c231c0ef5341716f3b to your computer and use it in GitHub Desktop.
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
| # 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