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 :: how to set the value of a variable null in python 
Python :: python subset 
Python :: write image out opencv 
Python :: how to declare global variable in python 
Python :: selenium python has no attrirute getText 
Python :: how to count repeated words in python 
Python :: python recursion factorial 
Python :: too many python versions pip package location 
Python :: highlight null/nan values in pandas table 
Python :: box plot python 
Python :: send api request python 
Python :: pygame surface 
Python :: django dumpdata specific app 
Python :: mount gdrive in pyton 
Python :: empty list in python 
Python :: PY | websocket - client 
Python :: generate random list and find max in list python 
Python :: NumPy unique Example Get unique values from a 1D Numpy array 
Python :: similarity imdex in python 
Python :: array creation method in numpy 
Python :: What does if __name_=="_main__": do? 
Python :: how to use assert in python 
Python :: python do while loop 
Python :: list pakages installed in python 
Python :: int to hex python without 0x 
Python :: how to set pandas dataframe as global 
Python :: how to make a bill in python 
Python :: python parse int as string 
Python :: get key from dict python 
Python :: read csv python 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =