Max Power
Max Power

Reputation: 83

Search in list string element by value

There is list in which the string line, how to search for the presence of value in the list? example value 'print'

tlist = ['Hello world',
       'Hello world print',
       'Text',
       'World hello print']

Upvotes: 0

Views: 42

Answers (2)

vks
vks

Reputation: 67968

tlist = ['Hello world',
   'Hello world print',
   'Text',
   'World hello print']

print [i for i in tlist if "print" in i]

Upvotes: 2

Avión
Avión

Reputation: 8386

for i in tlist:
    if 'print' in i:
         print '"print" is in the line"'

Upvotes: 0

Related Questions