w3resource

Python: Find numbers divisible by nineteen or thirteen from a list of numbers using Lambda

Python Lambda: Exercise-17 with Solution

Write a Python program to find numbers divisible by nineteen or thirteen from a list of numbers using Lambda.

Sample Solution:

Python Code :

# Create a list 'nums' containing integers
nums = [19, 65, 57, 39, 152, 639, 121, 44, 90, 190]

# Display a message indicating that the following output will show the original list
print("Orginal list:")
print(nums)  # Print the contents of the 'nums' list

# Use the 'filter()' function with a lambda function to filter numbers divisible by 19 or 13
# Filter elements from 'nums' using the lambda function to keep numbers divisible by 19 or 13
result = list(filter(lambda x: (x % 19 == 0 or x % 13 == 0), nums))

# Display numbers from the original list that are divisible by 19 or 13
print("\nNumbers of the above list divisible by nineteen or thirteen:")
print(result)  # Print the filtered 'result' list 

Sample Output:

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]

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: 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.
Next: Write a Python program to find palindromes in a given list of strings using Lambda.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/lambda/python-lambda-exercise-17.php