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 :: python break for loop 
Python :: get random float in range python 
Python :: flask python use specified port 
Python :: count item in list python 
Python :: random picker python 
Python :: difference between two dictionaries python 
Python :: python location 
Python :: print p py pyt pyth pytho python in python 
Python :: python series to list of string 
Python :: split string in python 
Python :: drop list of columns pandas 
Python :: python mixins 
Python :: pandas groupby mean 
Python :: check anonim user django 
Python :: leap year 
Python :: pandas datetime from date month year columns 
Python :: with python 
Python :: python switch case 3.10 
Python :: check if a list contains any item from another list python 
Python :: como comentar en Python? 
Python :: how to get the duration of audio python 
Python :: wintp python manage.py createsuperuser 
Python :: boto3 client python 
Python :: set type of column pandas 
Python :: how to convert a list to dataframe in python 
Python :: python one line if statement without else 
Python :: python hide print output 
Python :: how to make a column a factor in pandas 
Python :: deleting models with sqlalchemy orm 
Python :: what is the difference between python 2 and 3 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =