Posts

basic code

  # factorial of given number def factorial(n):             # single line to find factorial      return 1 if (n = = 1 or n = = 0 ) else n * factorial(n - 1 )   # Driver Code num = 5 print ( "Factorial of" ,num, "is" ,factorial(num)) ---------------------- Find Largest Element in list In this program, we have an array called array with some elements. We use the max function to find the largest element in the array. The key parameter is set to a  lambda function  lambda x: x, which simply returns the element itself. This lambda function is used to determine the comparison key for the max function. Python3       array = [ 10 , 5 , 20 , 8 , 15 ]   largest_element = max (array, key = lambda x: x) print ( "Largest element in the array:" , largest_element) def largest(arr, n):        # Initialize maximum element      max = arr[ 0 ...