Removing elements from a list containing specific characters

In addition to @Matth, if you want to combine multiple statements you can write:

l = ['1', '32', '523', '336']

[ x for x in l if "2" not in x and "3" not in x]

# Returns: ['1']

fString Example

l = ['1', '32', '523', '336']

stringValA = "2"
stringValB = "3"

print(f"{[ x for x in l if stringValA not in x and stringValB not in x ]}")

# Returns: ['1']

List comprehensions:

l = ['1', '32', '523', '336']

[ x for x in l if "2" not in x ]

# Returns: ['1', '336']

[ x for x in l if "2" in x ]

# Returns: ['32', '523']
l = ['1', '32', '523', '336']
stringVal = "2"

print(f"{[ x for x in l if stringVal not in x ]}")

# Returns: ['1', '336']

print(f"{[ x for x in l if stringVal in x ]}")

# Returns: ['32', '523']

If I understand you correctly,

Example:

l = ['1', '32', '523', '336']

[x for x in l if "2" not in x]

# Returns: ['1', '336']

fString Example:

l = ['1', '32', '523', '336']

stringVal = "2"

print(f"{[x for x in l if stringVal not in x]}")

# Returns: ['1', '336']

might do the job.