Question :-

  1. Define a Python function ascending(l) that returns True if each element in its input list is at least as big as the one before it.
    Here are some examples to show how your function should work.

    >>> ascending([])
    True
    >>> ascending([3,3,4])
    True
    >>> ascending([7,18,17,19])
    False
    

  2. A list of integers is said to be a valley if it consists of a sequence of strictly decreasing values followed by a sequence of strictlyincreasing values. The decreasing and increasing sequences must be of length at least 2. The last value of the decreasing sequence is the first value of the increasing sequence.
    Write a Python function valley(l) that takes a list of integers and returns True if l is a valley and False otherwise.
    Here are some examples to show how your function should work.

    >>> valley([3,2,1,2,3])
    True
    >>> valley([3,2,1])
    False
    >>> valley([3,3,2,1,2])
    False
    

  3. A two dimensional matrix can be represented in Python row-wise, as a list of lists: each inner list represents one row of the matrix. For instance, the matrix
    1  2  3
    4  5  6 
    

    would be represented as [[1,2,3],[4,5,6]].

    The transpose of a matrix makes each row into a column. For instance, the transpose of the matrix above is

    1  4  
    2  5
    3  6
    

    Write a Python function transpose(m) that takes as input a two dimensional matrix using this row-wise representation and returns the transpose of the matrix using the same representation.

    Here are some examples to show how your function should work. You may assume that the input to the function is always a non-empty matrix.

    >>> transpose([[1,4,9]])
    [[1], [4], [9]]
    
    >>> transpose([[1,3,5],[2,4,6]])
    [[1,2], [3,4], [5,6]]
    0 
    >>> transpose([[1,1,1],[2,2,2],[3,3,3]])
    [[1,2,3], [1,2,3], [1,2,3]]

Solution :-

Download Python File :- Download

def ascending(lst):
    for i in range(0, len(lst) - 1):
        if lst[i] > lst[i+1]:
            return False
    return True

def valley(lst):
    flag = False
    for i in range(0, len(lst) - 1):
        if lst[i] == lst[i+1]:
            return False
        if not flag:
            if lst[i] > lst[i+1]:
                continue
            if lst[i] < lst[i+1]:
                flag = True
        else:
            if lst[i] > lst[i+1]:
                return False
            elif lst[i] < lst[i+1]:
                continue
    return flag

def transpose(lst):
    return [list(x) for x in zip(*lst)]

 

Can be tested with the following code :-

print(ascending([]))
#True
print(ascending([3,3,4]))
#True
print(ascending([7,18,17,19]))
#False

print("Valley")
print(valley([3,2,1,2,3]))
print(valley([3, 2, 1]))
print(valley([3,3,2,1,2])))