improve truthtable tool
This commit is contained in:
parent
eba6a2c764
commit
62bede5eef
|
@ -2,14 +2,26 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
def is_number(x):
|
||||||
|
try:
|
||||||
|
_ = float(x)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def remove_numbers(seq):
|
||||||
|
return [ x for x in seq if not is_number(x)]
|
||||||
|
|
||||||
def remove_duplicates(seq):
|
def remove_duplicates(seq):
|
||||||
seen = set()
|
seen = set()
|
||||||
seen_add = seen.add
|
seen_add = seen.add
|
||||||
return [ x for x in seq if x not in seen and not seen_add(x)]
|
return [ x for x in seq if x not in seen and not seen_add(x)]
|
||||||
|
|
||||||
def get_operands(s):
|
def get_operands(s):
|
||||||
operands = remove_duplicates(sorted(re.findall("[A-z0-9_]+", s)))
|
operands = re.findall("[A-z0-9_]+", s)
|
||||||
return operands
|
operands = remove_duplicates(operands)
|
||||||
|
operands = remove_numbers(operands)
|
||||||
|
return sorted(operands)
|
||||||
|
|
||||||
def gen_truth_table(s):
|
def gen_truth_table(s):
|
||||||
operands = get_operands(s)
|
operands = get_operands(s)
|
||||||
|
|
Loading…
Reference in New Issue