user6066403
user6066403

Reputation: 213

Python how to delete a line in a table

I using Python and a function give me this output:

 [['2', 'prod1', 'Ela - Available'], ['2', 'prod1', 'Base - Replication logs']]

My goal it's to delete all lines contains "Available" with Python

So my goal it's to have:

[['2', 'prod1', 'Base - Replication logs']]

Upvotes: 0

Views: 608

Answers (2)

akash karothiya
akash karothiya

Reputation: 5950

Try this :

data = [['2', 'prod1', 'Ela - Available'], ['2', 'prod1', 'Base - Replication logs']]
output  = [line for line in data if not 'Available' in str(line)]
print(output)
[['2', 'prod1', 'Base - Replication logs']]

Upvotes: 4

Nehal J Wani
Nehal J Wani

Reputation: 16619

>>> l = [['2', 'prod1', 'Ela - Available'], ['2', 'prod1', 'Base - Replication logs']]
>>> filter(lambda x: not any('Available' in y for y in x), l)
[['2', 'prod1', 'Base - Replication logs']]

Upvotes: 4

Related Questions