

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print elements which are multiples of elements given in a list
When it is required to print the elements which are multiples of elements given in a list, a list comprehension is used.
Example
Below is a demonstration of the same
my_list = [45, 67, 89, 90, 10, 98, 10, 12, 23] print("The list is :") print(my_list) my_division_list = [6, 4] print("The division list is :") print(my_division_list) my_result = [element for element in my_list if all(element % j == 0 for j in my_division_list)] print("The result is :") print(my_result)
Output
The list is : [45, 67, 89, 90, 10, 98, 10, 12, 23] The division list is : [6, 4] The result is : [12]
Explanation
A list is defined and is displayed on the console.
Another list of integers is defined.
A list comprehension is used to iterate over the elements and check if the element divided by element in the integer list gives a remainder 0.
If yes, it is stored in a list and assigned to a variable.
This is displayed as output on the console.
- Related Questions & Answers
- C++ program to rearrange all elements of array which are multiples of x in increasing order
- Python Program that print elements common at specified index of list elements
- Python program to print all distinct elements of a given integer array.
- Program to find number of elements in all permutation which are following given conditions in Python
- Python - Ways to format elements of given list
- Print multiples of Unit Digit of Given Number in C Program
- Program to find list of elements which are less than limit and XOR is maximum in Python
- Write a program in Python to print the power of all the elements in a given series
- Python Program to replace list elements within a range with a given number
- Python program to find sum of elements in list
- C# program to print all distinct elements of a given integer array in C#
- Java program to print all distinct elements of a given integer array in Java
- Accessing all elements at given Python list of indexes
- Java Program to Print Boundary Elements of a Matrix
- Python program to print the duplicate elements of an array
Advertisements