Write a function that takes a single array as an argument (containing multiple strings and/or positive numbers and/or arrays), and returns one of four possible string values, depending on the ordering of the lengths of the elements in the input array:
Your function should return...
- “Increasing” - if the lengths of the elements increase from left to right (although it is possible that some neighbouring elements may also be equal in length)
- “Decreasing” - if the lengths of the elements decrease from left to right (although it is possible that some neighbouring elements may also be equal in length)
- “Unsorted” - if the lengths of the elements fluctuate from left to right
- “Constant” - if all element's lengths are the same.
Numbers and Strings should be evaluated based on the number of characters or digits used to write them.
Arrays should be evaluated based on the number of elements counted directly in the parent array (but not the number of elements contained in any sub-arrays).
Happy coding! :)
from operator import le, ge

size = lambda x: len(str(x)) if type(x) == int else len(x)
    
def order_type(arr):
    L = list(map(size, arr))
    if len(set(L)) <= 1: return "Constant"
    if all(map(le, L, L[1:])): return "Increasing"
    if all(map(ge, L, L[1:])): return "Decreasing"
    return "Unsorted"
from operator import le, ge

size = lambda x: len(str(x)) if type(x) == int else len(x)
    
def order_type(arr):
    L = list(map(size, arr))
    if len(set(L)) <= 1: return "Constant"
    if all(map(le, L, L[1:])): return "Increasing"
    if all(map(ge, L, L[1:])): return "Decreasing"
    return "Unsorted"