w3resource

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


17. Divisible by 19 or 13 Lambda

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]

For more Practice: Solve these Related Problems:

  • Write a Python program to find numbers divisible by both nineteen and thirteen using lambda.
  • Write a Python program to filter numbers that are divisible by nineteen but not by thirteen using lambda.
  • Write a Python program to identify numbers divisible by the sum of nineteen and thirteen using lambda.
  • Write a Python program to count the number of elements in a list that are divisible by either nineteen or thirteen using lambda.

Go to:


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.

Python Code Editor:

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

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.