Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python remove items from list containing string

>>> l = ['1', '32', '523', '336']
>>> [ x for x in l if "2" not in x ]
['1', '336']
>>> [ x for x in l if "2" in x ]
['32', '523']
Comment

if a list has a string remove

strings_with_substring = [string for string in strings if substring in string]
Comment

remove string from list in python

my_list = input("Enter your list splited by ',': ").split(',')
i = 0
while i < len(my_list):
    if my_list[i].isnumeric() == False:
        my_list.remove(my_list[i])
        i -= 1
    i += 1

print("List without str type: ",my_list)
Comment

PREVIOUS NEXT
Code Example
Python :: pyqt5 plain text edit get text 
Python :: notebook cell print output to file 
Python :: modern tkinter 
Python :: how to get SITE_ID in django....shell 
Python :: format date string python 
Python :: matplotlib legend get handles 
Python :: matlab filter in python 
Python :: selenium save page as image 
Python :: raise 400 error python 
Python :: python expand nested list 
Python :: Check if file already existing 
Python :: os.startfile 
Python :: most repeated character in a string python 
Python :: pandas divide multiple columns by one column 
Python :: python lastmonth 
Python :: pandas change column type 
Python :: django model example 
Python :: python print every n loops 
Python :: python temporary file 
Python :: Username Promt using Python with Character Limit 
Python :: python get name of vlue 
Python :: series to dataframe 
Python :: python while 
Python :: readlines 
Python :: python append to list 
Python :: tables in python 
Python :: python class arbitrary arguments 
Python :: python sort an array 
Python :: getting size of list in python 
Python :: how to merge two column pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =