- 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 remove a specific digit from every element of the list
When it is required to remove specific digit from every element of the list, an iteration and ‘set’ operator and ‘str’ methods are used.
Below is a demonstration of the same
my_list = [123, 565, 1948, 334, 4598] print("The list is :") print(my_list) key = 3 print("The key is :") print(key) my_result =  for element in my_list: if list(set(str(element))) == str(key) and len(set(str(element))) == 1: my_result.append('') else: my_result.append(int(''.join([element_1 for element_1 in str(element) if int(element_1) != key]))) print("The result is :") print(my_result)
The list is : [123, 565, 1948, 334, 4598] The key is : 3 The result is : 
- A list of integers is defined and is displayed on the console.
- A value for key is defined and is displayed on the console.
- An empty list is created.
- The list is iterated over, and the element at zeroth index is checked to match the key after converting it to a string, and to a set, and then to a list.
- The ‘and’ operator is also used to check if the specific element’s length is equal to 1.
- If yes, an empty space is appended to the empty list.
- Otherwise, it is converted into a string by iterating over it using list comprehension.
- This is done only if the element is not equal to key.
- This is again converted to an integer and is appended to the empty list.
- This is displayed as output on the console.
- Remove Tuples from the List having every element as None in Python
- Python – Remove Tuples from a List having every element as None
- How to remove an element from a list in Python?
- How to remove Specific Element from a Swift Array?
- Python program to Remove and print every third from list until it becomes empty?
- Python program to remove Duplicates elements from a List?
- Python Program to Remove Palindromic Elements from a List
- Remove a specific element from a LinkedList in Java
- How to remove a specific element from array in MongoDB?
- Python program to remove row with custom list element
- Java Program to remove an element from List with ListIterator
- How to remove an element from a Java List?
- How to remove an element from a list by index in Python?
- Python – Append given number with every element of the list