0% found this document useful (0 votes)
103 views13 pages

Lambdsfsdfca Exp. Questions

This document contains 38 questions about using lambda functions in Python. The questions cover a wide range of tasks including adding and multiplying numbers, sorting lists of tuples and dictionaries, filtering lists, mapping functions, and more. Lambda functions are used to solve each problem concisely.

Uploaded by

Naman Bansal
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)
103 views13 pages

Lambdsfsdfca Exp. Questions

This document contains 38 questions about using lambda functions in Python. The questions cover a wide range of tasks including adding and multiplying numbers, sorting lists of tuples and dictionaries, filtering lists, mapping functions, and more. Lambda functions are used to solve each problem concisely.

Uploaded by

Naman Bansal
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/ 13

Lambda Questions

1. Write a Python program to create a lambda function that adds 15 to a given


number passed in as an argument, also create a lambda function that
multiplies argument x with argument y and print the result. 
Sample Output:
25
48

2. Write a Python program to create a function that takes one argument, and
that argument will be multiplied with an unknown given number. 
Sample Output:
Double the number of 15 = 30
Triple the number of 15 = 45
Quadruple the number of 15 = 60
Quintuple the number 15 = 75

3. Write a Python program to sort a list of tuples using Lambda.


Original list of tuples:
[('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]
Sorting the List of Tuples:
[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]

4. Write a Python program to sort a list of dictionaries using Lambda. 


Original list of dictionaries :
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': '2',
'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]
Sorting the List of dictionaries :
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7,
'color': 'Blue'}, {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}]

5. Write a Python program to filter a list of integers using Lambda. 


Original list of integers:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Even numbers from the said list:
[2, 4, 6, 8, 10]
Odd numbers from the said list:
[1, 3, 5, 7, 9]

6. Write a Python program to square and cube every number in a given list of
integers using Lambda. 
Original list of integers:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Square every number of the said list:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Cube every number of the said list:
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

7. Write a Python program to find if a given string starts with a given character
using Lambda. 
Sample Output:
True
False

8. Write a Python program to extract year, month, date and time using
Lambda. 
Sample Output:
2020-01-15 09:03:32.744178
2020
1
15
09:03:32.744178

9. Write a Python program to check whether a given string is number or not


using Lambda. 
Sample Output:
True
True
False
True
False
True
Print checking numbers:
True
True

10. Write a Python program to create Fibonacci series upto n using Lambda. 


Fibonacci series upto 2:
[0, 1]
Fibonacci series upto 5:
[0, 1, 1, 2, 3]
Fibonacci series upto 6:
[0, 1, 1, 2, 3, 5]
Fibonacci series upto 9:
[0, 1, 1, 2, 3, 5, 8, 13, 21]

11. Write a Python program to find intersection of two given arrays using


Lambda. 
Original arrays:
[1, 2, 3, 5, 7, 8, 9, 10]
[1, 2, 4, 8, 9]
Intersection of the said arrays: [1, 2, 8, 9]

12. Write a Python program to rearrange positive and negative numbers in a


given array using Lambda. 
Original arrays:
[-1, 2, -3, 5, 7, 8, 9, -10]
Rearrange positive and negative numbers of the said array:
[2, 5, 7, 8, 9, -10, -3, -1]

13. Write a Python program to count the even, odd numbers in a given array
of integers using Lambda. 
Original arrays:
[1, 2, 3, 5, 7, 8, 9, 10]
Number of even numbers in the above array: 3
Number of odd numbers in the above array: 5
14. Write a Python program to find the values of length six in a given list using
Lambda. 
Sample Output:
Monday
Friday
Sunday

15. Write a Python program to add two given lists using map and lambda. 
Original list:
[1, 2, 3]
[4, 5, 6]
Result: after adding two list
[5, 7, 9]

16. Write a Python program to find the second lowest grade of any student(s)
from the given names and grades of each student using lists and lambda.
Input number of students, names and grades of each student. 
Input number of students: 5
Name: S ROY
Grade: 1
Name: B BOSE
Grade: 3
Name: N KAR
Grade: 2
Name: C DUTTA
Grade: 1
Name: G GHOSH
Grade: 1
Names and Grades of all students:
[['S ROY', 1.0], ['B BOSE', 3.0], ['N KAR', 2.0], ['C DUTTA', 1.0], ['G GHOSH',
1.0]]
Second lowest grade: 2.0
Names:
N KAR
17. Write a Python program to find numbers divisible by nineteen or thirteen
from a list of numbers using Lambda. 
Orginal list:
[19, 65, 57, 39, 152, 639, 121, 44, 90, 190]
Numbers of the above list divisible by nineteen or thirteen:
[19, 65, 57, 39, 152, 190]

18. Write a Python program to find palindromes in a given list of strings using


Lambda. 
Orginal list of strings:
['php', 'w3r', 'Python', 'abcd', 'Java', 'aaa']
List of palindromes:
['php', 'aaa']

19. Write a Python program to find all anagrams of a string in a given list of


strings using lambda. 
Orginal list of strings:
['bcda', 'abce', 'cbda', 'cbea', 'adcb']
Anagrams of 'abcd' in the above string:
['bcda', 'cbda', 'adcb']

20. Write a Python program to find the numbers of a given string and store
them in a list, display the numbers which are bigger than the length of the list
in sorted form. Use lambda function to solve the problem. 
Original string: sdf 23 safs8 5 sdfsd8 sdfs 56 21sfs 20 5
Numbers in sorted form:
20 23 56

21. Write a Python program that multiply each number of given list with a
given number using lambda function. Print the result. 
Original list: [2, 4, 6, 9, 11]
Given number: 2
Result:
4 8 12 18 22
22. Write a Python program that sum the length of the names of a given list of
names after removing the names that starts with an lowercase letter. Use
lambda function. 
Result:
16

23. Write a Python program to calculate the sum of the positive and negative
numbers of a given list of numbers using lambda function. 
Original list: [2, 4, -6, -9, 11, -12, 14, -5, 17]
Sum of the positive numbers: -32
Sum of the negative numbers: 48

24. Write a Python program to find numbers within a given range where every
number is divisible by every digit it contains. 
Sample Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]

25. Write a Python program to create the next bigger number by rearranging


the digits of a given number. 
Original number: 12
Next bigger number: 21
Original number: 10
Next bigger number: False
Original number: 201
Next bigger number: 210
Original number: 102
Next bigger number: 120
Original number: 445
Next bigger number: 454

26. Write a Python program to find the list with maximum and minimum length
using lambda. 
Original list:
[[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]]
List with maximum length of lists:
(3, [13, 15, 17])
List with minimum length of lists:
(1, [0])

27. Write a Python program to sort each sublist of strings in a given list of lists
using lambda. 
Original list:
[['green', 'orange'], ['black', 'white'], ['white', 'black', 'orange']]
After sorting each sublist of the said list of lists:
[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]

28. Write a Python program to sort a given list of lists by length and value
using lambda. 
Original list:
[[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]]
Sort the list of lists by length and value:
[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]

29. Write a Python program to find the maximum value in a given


heterogeneous list using lambda. 
Original list:
['Python', 3, 2, 4, 5, 'version']
Maximum values in the said list using lambda:
5

30. Write a Python program to sort a given matrix in ascending order


according to the sum of its rows using lambda. 
Original Matrix:
[[1, 2, 3], [2, 4, 5], [1, 1, 1]]
Sort the said matrix in ascending order according to the sum of its rows
[[1, 1, 1], [1, 2, 3], [2, 4, 5]]
Original Matrix:
[[1, 2, 3], [-2, 4, -5], [1, -1, 1]]
Sort the said matrix in ascending order according to the sum of its rows
[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]
31. Write a Python program to extract specified size of strings from a give list
of string values using lambda. 
Original list:
['Python', 'list', 'exercises', 'practice', 'solution']
length of the string to extract:
8
After extracting strings of specified length from the said list:
['practice', 'solution']

32. Write a Python program to count float number in a given mixed list using
lambda. 
Original list:
[1, 'abcd', 3.12, 1.2, 4, 'xyz', 5, 'pqr', 7, -5, -12.22]
Number of floats in the said mixed list:
3

33. Write a Python program to check whether a given string contains a capital


letter, a lower case letter, a number and a minimum length using lambda. 
Input the string: W3resource
['Valid string.']

34. Write a Python program to filter the height and width of students, which
are stored in a dictionary using lambda. 
Original Dictionary:
{'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68),
'Pierre Cox': (5.8, 66)}
Height> 6ft and Weight> 70kg:
{'Cierra Vega': (6.2, 70)}

35. Write a Python program to check whether a specified list is sorted or not


using lambda. 
Original list:
[1, 2, 4, 6, 8, 10, 12, 14, 16, 17]
Is the said list is sorted!
True
Original list:
[1, 2, 4, 6, 8, 10, 12, 14, 16, 17]
Is the said list is sorted!
False

36. Write a Python program to extract the nth element from a given list of
tuples using lambda. 
Original list:
[('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94),
('Beau Turnbull', 94, 98)]
Extract nth element ( n = 0 ) from the said list of tuples:
['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull']
Extract nth element ( n = 2 ) from the said list of tuples:
[99, 96, 94, 98]

37. Write a Python program to sort a list of lists by a given index of the inner
list using lambda. 
Original list:
[('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94),
('Beau Turnbull', 94, 98)]
Sort the said list of lists by a given index ( Index = 0 ) of the inner list
[('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99),
('Wyatt Knott', 91, 94)]
Sort the said list of lists by a given index ( Index = 2 ) of the inner list
[('Wyatt Knott', 91, 94), ('Brady Kent', 97, 96), ('Beau Turnbull', 94, 98),
('Greyson Fulton', 98, 99)]

38. Write a Python program to remove all elements from a given list present in
another list using lambda. 
Original lists:
list1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
list2: [2, 4, 6, 8]
Remove all elements from 'list1' present in 'list2:
[1, 3, 5, 7, 9, 10]

39. Write a Python program to find the elements of a given list of strings that
contain specific substring using lambda. 
Original list:
['red', 'black', 'white', 'green', 'orange']
Substring to search:
ack
Elements of the said list that contain specific substring:
['black']
Substring to search:
abc
Elements of the said list that contain specific substring:
[]

40. Write a Python program to find the nested lists elements, which are
present in another list using lambda. 
Original lists: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]]
Intersection of said nested lists:
[[12], [7, 11], [1, 5, 8]]

41. Write a Python program to reverse strings in a given list of string values


using lambda. 
Original lists:
['Red', 'Green', 'Blue', 'White', 'Black']
Reverse strings of the said given list:
['deR', 'neerG', 'eulB', 'etihW', 'kcalB']

42. Write a Python program to calculate the product of a given list of numbers


using lambda. 
list1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Product of the said list numbers:
3628800
list2: [2.2, 4.12, 6.6, 8.1, 8.3]
Product of the said list numbers:
4021.8599520000007

43. Write a Python program to multiply all the numbers in a given list using
lambda. 
Original list:
[4, 3, 2, 2, -1, 18]
Mmultiply all the numbers of the said list: -864
Original list:
[2, 4, 8, 8, 3, 2, 9]
Mmultiply all the numbers of the said list: 27648

44. Write a Python program to calculate the average value of the numbers in a


given tuple of tuples using lambda. 
Original Tuple:
((10, 10, 10), (30, 45, 56), (81, 80, 39), (1, 2, 3))
Average value of the numbers of the said tuple of tuples:
(30.5, 34.25, 27.0)
Original Tuple:
((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3))
Average value of the numbers of the said tuple of tuples:
(25.5, -18.0, 3.75)

45. Write a Python program to convert string element to integer inside a given


tuple using lambda. 
Original tuple values:
(('233', 'ABCD', '33'), ('1416', 'EFGH', '55'), ('2345', 'WERT', '34'))
New tuple values:
((233, 33), (1416, 55), (2345, 34))

46. Write a Python program to find index position and value of the maximum
and minimum values in a given list of numbers using lambda. 
Original list:
[12, 33, 23, 10.11, 67, 89, 45, 66.7, 23, 12, 11, 10.25, 54]
Index position and value of the maximum value of the said list:
(5, 89)
Index position and value of the minimum value of the said list:
(3, 10.11)

47. Write a Python program to sort a given mixed list of integers and strings
using lambda. Numbers must be sorted before strings. 
Original list:
[19, 'red', 12, 'green', 'blue', 10, 'white', 'green', 1]
Sort the said mixed list of integers and strings:
[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']

48. Write a Python program to sort a given list of strings(numbers) numerically


using lambda. 
Original list:
['4', '12', '45', '7', '0', '100', '200', '-12', '-500']
Sort the said list of strings(numbers) numerically:
['-500', '-12', '0', '4', '7', '12', '45', '100', '200']

49. Write a Python program to count the occurrences of the items in a given


list using lambda. 
Original list:
[3, 4, 5, 8, 0, 3, 8, 5, 0, 3, 1, 5, 2, 3, 4, 2]
Count the occurrences of the items in the said list:
{3: 4, 4: 2, 5: 3, 8: 2, 0: 2, 1: 1, 2: 2}

50. Write a Python program to remove specific words from a given list using
lambda. 
Original list:
['orange', 'red', 'green', 'blue', 'white', 'black']
Remove words:
['orange', 'black']
After removing the specified words from the said list:
['red', 'green', 'blue', 'white']

51. Write a Python program to find the maximum and minimum values in a


given list of tuples using lambda function. 
Original list with tuples:
[('V', 62), ('VI', 68), ('VII', 72), ('VIII', 70), ('IX', 74), ('X', 65)]
Maximum and minimum values of the said list of tuples:
(74, 62)
52. Write a Python program to remove None value from a given list using
lambda function. 
Original list:
[12, 0, None, 23, None, -55, 234, 89, None, 0, 6, -12]
Remove None value from the said list:
[12, 0, 23, -55, 234, 89, 0, 6, -12]

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