SC37 Rushan Shaikh Assign.6
SC37 Rushan Shaikh Assign.6
NAME-RUSHAN SHAIKH
CLASS-SY CSE-C
DESCRIPTION
Functions In Python
A function is a block of code that performs a specific task. Dividing a complex problem into smaller
chunks makes our program easy to understand and reuse.
1)Standard library functions - These are built-in functions in Python that are available to use.
2)User-defined functions - We can create our own functions based on our requirements.
def function_name(arguments):
# function body
return
A function can also have arguments. An argument is a value that is accepted by a function.
A Python function may or may not return a value. If we want our function to return some value to a
function call, we use the return statement.
Python Lambda Functions are anonymous function means that the function is without a name. As
we already know that the def keyword is used to define a normal function in Python. Similarly, the
lambda keyword is used to define an anonymous function in Python.
This function can have any number of arguments but only one expression, which is
evaluated and returned.
One is free to use lambda functions wherever function objects are required.
Lambda functions are syntactically restricted to a single expression.
It has various uses in particular fields of programming, besides other types of expressions in
functions.
Syntax:
IMPLEMENTATION
1. Write a Python program to filter a list of even integers using Lambda function from given list
of integers.
Program
Output
2. Write a Python program to filter a list of odd integers using Lambda function from given list
of integers.
Output: [1, 3, 5, 7, 9]
Program
Output
3. Write a Python program to filter a list of integers that are divisible by 3 using Lambda
Output: [ 3, 6, 9]
Program
Output
4. Write a Python program to square and cube every number in a given list of integers using
Lambda function.
Square every number of the input list:[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Cube every number of the input list:[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
Program
Output
year, month, date and time using Lambda from current date.
Output:
2023
15
09:03:32.744178
Program
Output
6. Write a Python program to sort a list of dictionaries using Lambda function based on
make/model/color.
Input: [{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': 2,
'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]
Output: Sorted the List of dictionaries based on color: [{'make': 'Nokia', 'model': 216,
'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2,
'color': 'Gold'}]
Sorted the List of dictionaries based on make: [{'make': 'Mi Max', 'model': 2, 'color': 'Gold'},
{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]
[{'make': 'Mi Max', 'model': 2, 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'},
Program
Output
7. Write a Python program to sort a list of tuples using Lambda function based on subject name
and marks.
Input: [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]
Output:
Sorted List of Tuples based on subject name: [('English', 88), ('Maths', 97), ('Science', 90),
Sorted List of Tuples based on marks obtained: [('Social sciences', 82), ('English', 88),
Program
Output