Essay Examples on Hartpury College

Import Sys Reduces the operators if and is present inside

Import Sys Reduces the operators if and is present inside and or or inside or Example and A and B C should be and A B C def reduceOperators formula if isinstance formula str return formula operator formula 0 literals propositions for index item in enumerate formula if index 0 if isinstance item str literals append item elif isinstance item list propositions append reduceOperators item newFormula literals for item in propositions if isinstance item list and item 0 operator for i clause in enumerate item if i 0 newFormula append clause else newFormula append item newFormula insert 0 operator return newFormula Removes duplicate elements from and and or Example and A A should be A def removeDuplicates formula if isinstance formula str or isinstance formula list and formula 0 not and isinstance formula 1 str return formula for i checkItem in enumerate formula if i 



1 pages | 276 words
Save