From 9dc18ba8df901740df31893483a87db101830fa6 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 11 Aug 2019 03:45:55 -0500 Subject: [PATCH] eliminateEmpty config --- README.md | 6 +++++- __pycache__/fusion.cpython-37.pyc | Bin 3557 -> 3626 bytes config.json | 3 ++- fusion.py | 23 +++++++++++++++++------ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8977ceb..8edcc11 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,8 @@ A set of elements with the score (-1, 5) would get filtered out, while a set wit --- -`fullPrint` refers to whether it should print out the Symbol or the Name of the Element \ No newline at end of file +`fullPrint` refers to whether it should print out the Symbol or the Name of the Element + +--- + +`eliminateEmpty` refers to whether the program should remove specified elements if they contained no matching tuples. \ No newline at end of file diff --git a/__pycache__/fusion.cpython-37.pyc b/__pycache__/fusion.cpython-37.pyc index ebafa185640b945f9f87e3f86218a13f5b228bdb..71858df71e140469f54cc435de4ffac1b685462d 100644 GIT binary patch delta 1212 zcmaJ=O-vI(6yDjNcG_-#C>Yy706~5h2?EN&KuA>3#KfwpF|iSo(phk&-8Qp>k-r!% zM?K)2^rBoma5Wyhn0V#jO%EFnX!L*=f@EUJ##COA&<8PuH7ian88AuO2K5|z{VL3Y=T8t6#ge!jG16lEY1>OTUe5% zz@{0=D^|-s-kDpCm8$N7vp90stGYhn@+UpLwfihhr^?03JS$GeAj-o~Daa+uH@s4n z+ZOS4N7xk}21i3t+(kf{Af6(BsF(ZjtVKBfIVdvTi2Oyqk(B(T9)G>Al?chmJ-v%` zJ~h5jkz7zA)s);f7KkOUhTQC7cMZwUp}8U7yi@dY_F_>u_iV2T^oT5kb0>TnRFhw> zaJ_k|qw+&|w7b7~(75cR&q{S-J#Ai*M_k%99d-fj6iGB^nnAdJQYh!9MG zwyCTuGfJJn6reB6qFFe@Vo$WXT35G8oe+g7K&vS)M(_7_!c~^ayTJIw{=ZFF#-#ij z9lM3l21p*nYXil|OF&|37PXdDwy{-uZq-=Zh^}pLjORGF(1m2f9M-$Da>wj`P{I?q z&?0LAQU*2xu(AqoYoH0Tq~!rIKr1BdvQu%~qOfNxHL(&PUWa+_!#*4FshUCk2yYZ2DU+K6hcW_ z4-u6#B%y`~p9HVf>Z?`H*Sr<4pyP|@8Ci&rT9^{Y*UE9kc^|4HsBk(sG7=o;VfkKf g?Wa?fDqAkw)7Ys1a8PR_DNWZX08@=pnxL(J0qB|G4gdfE delta 1105 zcmaJ=OHUL*5bm0tnVsF8*%z|B42z(!V*&yp(HP+1>%ak`oWyWgwg(*CoyG0}l}Aj3 zgNe}u`=XxoYT}8zKf!pO8;KrFym%qTgIcvbLJV;xT~*!vb$wM`)$dP#?MPp7oFv2V z*XOC(oz!-^6`pSQ-Mqz(EjE+lCXb`Gxy2Kx9iHSV)M;*W2X%(0c?NZsXL$~Fj>9x_ z^WVtdcTT|UuuK`^#LXfkw8=ZhL)DdY5=B}YqWHL z5w?1%eF0lNh@Dk~+L%RqE{K%+;WV||cgu3pTPTPAiYJ?nohs}+i%EbM^+zv4Q5B6{ zi)ZIGj4-Dxa~?{nZU#V3nyqTNHpk23uG%wa&xpc-e^erVBrLLeQS_^g_++oJX|AK7 zP{=+3dO_{Q2fGOQAJCAxVZDJawQKcddJsB-qmjDFwm*$%Zbr2wZtJcty490JPg^%} zQ81A+=gDx|t9q5tuLtMU$3(GX7&j_78Xuq}?z_gR})>RBJlprk3zky_L4(BmD0d5jYGDhSU`^1{04Bg z$U<00zc1Lfc3(%&uxhMrB-b|3Zw8Tq;yvQHeiFwhc_j*ysm@fP*otPzIB<TWZy}HKl6DHR Onia!8Zs}IqYWfQ`U*X#T diff --git a/config.json b/config.json index 2d619d6..0403b8e 100644 --- a/config.json +++ b/config.json @@ -123,5 +123,6 @@ "reverseInnerOrder": false, "reverseOrder" : false, "noNegatives" : true, - "fullPrint" : true + "fullPrint" : true, + "eliminateEmpty" : false } \ No newline at end of file diff --git a/fusion.py b/fusion.py index 599cdc9..38a4648 100644 --- a/fusion.py +++ b/fusion.py @@ -4,6 +4,9 @@ import os, sys, json, re, mendeleev as mdv path = os.path.join(sys.path[0], 'config.json') config = json.load(open(path, 'r')) +# Constants +noElements = '\t{No elements matched the configuration specified}' + # Lambdas score = lambda element : config['elements'][str(element)] scoreSum = lambda item : ((score(item[0]) + score(item[1])), item) @@ -48,16 +51,24 @@ def bestSelection(select): # Build the strings string1 = '[Best Elements for Element {}, {}]'.format(select, mdv.element(select).name if config['fullPrint'] else mdv.element(select.symbol)) string2 = '\n'.join([formatting(element1, element2) for element1, element2 in posi]) - return string1, string2 or '\t{No elements matched the configuration specified}' + return string1, string2 or noElements # Driver code def main(): selection = input("Choose elements, delimited by whitespace and/or punctuation...\n") selection = [getElement(e) for e in selection.split()] + # No one: + # No one at all: + # Me: print('\n\n'.join( - sorted(['{}\n{}'.format(*bestSelection(E)) for E in selection], - # hacky solution for reverseOrder config option - key=lambda string : len([line for line in string.split('\n') if - '\t{No elements matched the configuration specified}' not in line]), - reverse=not config['reverseOrder']) + map( + lambda item : '{}\n{}'.format(item[0], item[1]), + filter( + lambda item : (item[1] != noElements) if config['eliminateEmpty'] else True, + sorted([bestSelection(E) for E in selection], + # hacky solution for reverseOrder config option + key=lambda item : len(item[1]) if item[1] != noElements else 0, + reverse=not config['reverseOrder']) + ) + ) )) \ No newline at end of file