X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=szyfrow%2Fsupport%2Futilities.py;h=80008e9629dfb9d06eda531406a7958fcb3a9fdc;hb=refs%2Fheads%2Fmain;hp=7a61ae709a55d2115118991bc78f860caf1ad66b;hpb=3350a462f460e81d96c587466f5b6a88cbba1f7e;p=szyfrow.git diff --git a/szyfrow/support/utilities.py b/szyfrow/support/utilities.py index 7a61ae7..80008e9 100644 --- a/szyfrow/support/utilities.py +++ b/szyfrow/support/utilities.py @@ -1,16 +1,18 @@ +"""A mish-mash of utility functions""" + import string import collections import unicodedata from itertools import zip_longest -# join a a list of letters into a string cat = ''.join +"""join a a list of letters into a string.""" -# join a list of words into a string, separated by spaces wcat = ' '.join +"""join a list of words into a string, separated by spaces""" -# join a list of lines, separated by newline lcat = '\n'.join +"""join a list of lines, separated by newline""" def pos(letter): """Return the position of a letter in the alphabet (0-25)""" @@ -122,6 +124,9 @@ def untranspose(items, transposition): return transposed def deduplicate(text): + """Return the input string, but with second (and subsequent) occurrences + of a character removed. + """ return list(collections.OrderedDict.fromkeys(text)) @@ -172,6 +177,9 @@ def sanitise(text): def index_of_coincidence(text): + """Index of coincidence of a string. This is low for random text, + higher for natural langauge. + """ stext = sanitise(text) counts = collections.Counter(stext) denom = len(stext) * (len(text) - 1) / 26