- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 mask a list using values from another list
When it is required to mask a list with the help of values from another list, list comprehension is used.
Below is a demonstration of the same
my_list = [5, 6, 1, 9, 11, 0, 4] print("The list is :") print(my_list) search_list = [2, 10, 6, 3, 9] result = [1 if element in search_list else 0 for element in my_list] print("The result is :") print(result)
The list is : [5, 6, 1, 9, 11, 0, 4] The result is : [0, 1, 0, 1, 0, 0, 0]
A list is defined and is displayed on the console.
Another list of elements is defined.
The list comprehension is used to iterate through the list and search for the element in the list.
The results are assigned to a variable.
This result is displayed on the console.
- Python Program to print unique values from a list
- How to remove index list from another list in python?
- Java Program to copy value from one list to another list
- Update a list of tuples using another list in Python
- Python - Filter even values from a list
- Python - Insert list in another list
- C# program to print unique values from a list
- Java program to print unique values from a list
- Get unique values from a list in Python
- Python program to extract Keywords from a list
- Program to find folded list from a given linked list in Python
- Python - Check if a list is contained in another list
- Python | Sort the values of first list using second list
- Java Program to create a new list with values from existing list with Function Mapper
- Java Program to create a new list with values from existing list with Lambda Expressions