PKX(L)y minimalkeys.py"Compute the minimal keys for a collection of strings or sequences." __version__ = "0.1.0" import re def minimal_keys(keys, *, key=None, split=r'(\w+)'): """Compute the minimal keys for a collection of string. Parameters ---------- items : [str] A sequence of keys. key: function A function of one argument that normalizes substrings before they are tested for equality. split: str A regular expression string that is used to split the string into the substrings that are candidates for removal. It should capture characters that should be included in the resulting minimal keys. Returns ------- str A sequence of keys. Examples -------- >>> minimal_keys(['assignments/alice/hw1.txt', 'assignments/bob/hw1.txt']) ['alice', 'bob'] >>> minimal_keys(['alice/assignments/hw1.txt', 'bob/assignments/hw1.txt']) ['alice', 'bob'] >>> minimal_keys(['assignments/alice.txt', 'Assignments/bob.txt']) ['assignments/alice', 'Assignments/bob'] >>> minimal_keys(['assignments/alice.txt', 'Assignments/bob.txt'], key=str.upper) ['alice', 'bob'] >>> minimal_keys(['assignments/alice_smith.txt', 'assignments/alice_jones.txt']) ['alice_smith', 'alice_jones'] >>> minimal_keys(['assignments/alice_smith.txt', 'assignments/alice_jones.txt'], \ split=r'([a-z]+)') ['smith', 'jones'] """ splitter = re.compile(split).split keys = list(map(splitter, keys)) keys = minimal_seq_keys(keys, key) return list(map(''.join, keys)) def minimal_seq_keys(keys, key=None): """Compute the minimal keys for a collection of sequences. Parameters ---------- items : [seq] A sequence of keys. Each key is itself a sequence. key: function A function of one argument that normalizes substrings before they are tested for equality. Returns ------- seq A sequence of keys. """ key = key or (lambda k: k) def trim(keys, ix, s0, s1): "Return a list k[s0:s1] if all the k[ix] are equivalent under key." while all(keys) and len(set(key(k[ix]) for k in keys)) == 1: keys = [k[s0:s1] for k in keys] return keys keys = trim(keys, 0, 1, None) keys = trim(keys, -1, None, -1) if any(not k for k in keys): raise Exception("duplicate keys") return keys PK&U(L<--#minimalkeys-0.1.0.dist-info/LICENSEMIT License Copyright (c) 2018 Oliver Steele Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.PK!HxQP!minimalkeys-0.1.0.dist-info/WHEEL1 0 RZq+D-Dv;_[*7Fp 8MRq%_:==ߘPT PK!Hj  $minimalkeys-0.1.0.dist-info/METADATAUn7}W ji7n>,`BB|CA`Q]6\rKrC?_/ w%KrU-'-993C,dyeMR֘A+/6/䅘u-*7nڀ*\`aHȭ֘B]NmyEOOQ#KX,MKvNӞ|՜'W\q*2jӯJg2@*C?^Q$;=yo^-.QۦFVCKX7܉mTG\M'0ngz{rldM(\q|'sB\3vzu=e7XpfӶi T^>tpS) nC[2DP ^瀣BU֍c%x6t* O&Oiuwh(v6v==6Mѝõny "b0> ~y ef$d'Me+ijTL'~YƤYؤHb]agR:D)m_Z\wJCw^t.׽=K|۰dlI;d:D}NsyRY_v_۾,ћ$Uͪ/KZ]_h;E5X(+qBPK!H}"minimalkeys-0.1.0.dist-info/RECORD}Kr0нgIh@qE؊DvMP@@f}WLw^{Z<{UNNn|qrd(2lػ[M<DS@+x3)(j|x!!X;T5 W%%Ͱ8[׶@[;ԛf q^^2ߜgC5=}ta[RR`?hD>^uZHNm^uKӎûnoPKX(L)y minimalkeys.pyPK&U(L<--# minimalkeys-0.1.0.dist-info/LICENSEPK!HxQP!Tminimalkeys-0.1.0.dist-info/WHEELPK!Hj  $minimalkeys-0.1.0.dist-info/METADATAPK!H}"minimalkeys-0.1.0.dist-info/RECORDPK~T