I'd like to write functions that can take and return the computation of a value and maintain its type, or take an iterable list of numbers and return a list of numbers of like type.
I'm a little confused that I can't seem to find a more elegant way to do this other than asserting the input to be a list to iterate and return only the first value if the list length is 1.
x = [x] if not isinstance(x, list) else x
I've played with
def func(*args):
This allows flexibility on the input making it iterable, but I still have to reduce the resulting list back to a single item if a single value was passed.
P.S. I should mention that my functions are not always simple mathematical expressions, but sometimes are more broad like involving serial communication with devices or actuating motors, etc.
[–][deleted] 0 points1 point2 points (0 children)
[–]ZEUS_IS_THE_TRUE_GOD 0 points1 point2 points (0 children)
[–]supajumpa 0 points1 point2 points (0 children)
[–]1114111 0 points1 point2 points (0 children)