X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=cipher.py;fp=cipher.py;h=c5d542bb915b4cfd0775d5c100e8dce46a271d88;hb=e0b8557e10493b6e54209a6cdf463e39634cfbfd;hp=59eb3a6223ccea3814256e6f05b5d0c30b000cfa;hpb=394bcd0c89bbc6de8e9473002a27c673ee8daa43;p=cipher-tools.git diff --git a/cipher.py b/cipher.py index 59eb3a6..c5d542b 100644 --- a/cipher.py +++ b/cipher.py @@ -19,18 +19,6 @@ for a in range(26): modular_division_table[b][c] = a -def ngrams(text, n): - """Returns all n-grams of a text - - >>> ngrams(sanitise('the quick brown fox'), 2) # doctest: +NORMALIZE_WHITESPACE - ['th', 'he', 'eq', 'qu', 'ui', 'ic', 'ck', 'kb', 'br', 'ro', 'ow', 'wn', - 'nf', 'fo', 'ox'] - >>> ngrams(sanitise('the quick brown fox'), 4) # doctest: +NORMALIZE_WHITESPACE - ['theq', 'hequ', 'equi', 'quic', 'uick', 'ickb', 'ckbr', 'kbro', 'brow', - 'rown', 'ownf', 'wnfo', 'nfox'] - """ - return [text[i:i+n] for i in range(len(text)-n+1)] - def every_nth(text, n, fillvalue=''): """Returns n strings, each of which consists of every nth character, starting with the 0th, 1st, 2nd, ... (n-1)th character