0% found this document useful (0 votes)
10 views5 pages

SC37 Rushan Shaikh Assign.6

Uploaded by

ARNY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

SC37 Rushan Shaikh Assign.6

Uploaded by

ARNY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT NUMBER 6

NAME-RUSHAN SHAIKH

CLASS-SY CSE-C

ROLL NO- SC37

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.

There are two types of function in Python programming:

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.

The syntax to declare a function is:

def function_name(arguments):

# function body

return

def - keyword used to declare a function

function_name - any name given to the function

arguments - any value passed to function

return (optional) - returns value from a function

Python Function Arguments

A function can also have arguments. An argument is a value that is accepted by a function.

The return Statement in Python

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

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:

lambda arguments : expression

IMPLEMENTATION

1. Write a Python program to filter a list of even integers using Lambda function from given list

of integers.

Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Output: [2, 4, 6, 8, 10]

Program

Output

2. Write a Python program to filter a list of odd integers using Lambda function from given list

of integers.

Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

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

function from given list of integers.

Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

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.

Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

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

5. Write a Python program to extract

year, month, date and time using Lambda from current date.

Input: 2023-04-15 09:03:32.744178

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'}]

Sorted the List of dictionaries based on model:

[{'make': 'Mi Max', 'model': 2, 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'},

{'make': 'Nokia', 'model': 216, 'color': 'Black'}]

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),

('Social sciences', 82)]

Sorted List of Tuples based on marks obtained: [('Social sciences', 82), ('English', 88),

('Science', 90), ('Maths', 97)]

Program

Output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy