- 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 - Check if list contain particular digits
When it is required to check if a list contains particular digits, the ‘join’ method, and a simple iteration are used.
Below is a demonstration of the same
my_list = [415, 133, 145, 451, 154] print("The list is :") print(my_list) my_digits = [1, 4, 5, 3] digit_string = ''.join([str(ele) for ele in my_digits]) all_elems = ''.join([str(ele) for ele in my_list]) my_result = True for element in all_elems: for ele in element: if ele not in digit_string: my_result = False break if(my_result == True): print("All elements have been made from required digits") else: print("All elements haven't been made from required digits")
The list is : [415, 133, 145, 451, 154] All elements have been made from required digits
A list is defined and is displayed on the console.
Another list with integers is defined.
The list comprehension is used to iteated through the second list, and join them.
This is assigned to a variable.
Another list comprehension is used to iterate over the first list and join them.
This is assigned to another variable.
Another result variable is initially assigned to ‘True’.
The second variable is iterated over, and if it is not found in the first variable, the result variable is assigned to ‘False’.
If result is still ‘True’ after coming out of the condition, relevant message is displayed on the console.
- Python - Check if a List contain particular digits
- Python Pandas - Check elementwise if the Intervals contain the value
- How to check if a Python string contains only digits?
- Checking if starting digits are similar in list in Python
- Python Pandas - Check elementwise if the Intervals in the IntervalIndex contain the value
- Python - Check if a list is contained in another list
- Check if all digits of a number divide it in Python
- Check if list contains consecutive numbers in Python
- Check if list is strictly increasing in Python
- Check elementwise if the Intervals in the IntervalIndex contain the value in Python Pandas
- Python – Check if particular value is present corresponding to K key
- Python Program for Check if all digits of a number divide it
- Check if a particular element exists in Java LinkedHashSet
- Check if a particular key exists in Java LinkedHashMap
- Check if a particular value exists in Java LinkedHashMap