def list_modulo(ls, op, comp): """Lists all the elements in the list which fit in the given condition Input data: ls -- The list op -- function object to be used for the condition comp -- integer to use for the condition Output data: The list of all the numbers that fit in the condition """ return [n for n in ls if op(float(ComplexNumber.modulo(n)), comp)]
def filter_modulo(ls, op, comp, **kwargs): """Filters out all numbers that dont fit in the given condition Input data: ls -- The list to be filtered op -- The function name to be used by the condition comp -- The integer to be used for the condition Output data: The filtered list """ if "undo" in kwargs: kwargs["undo_id"] = Undo.choose_undo_id(kwargs) for i, x in reversed(list(enumerate(ls))): if not op(float(ComplexNumber.modulo(x)), comp): remove(ls, i, i, **kwargs) return ls
def modulo(): assert (ComplexNumber.modulo(cn(1)) == 1) assert (ComplexNumber.modulo(cn(2j)) == 2) assert (ComplexNumber.modulo(cn(3 + 4j)) == 5)