Search or find a element inside list python

I have a list as follows:

[u'12:13-internet-wifi-primary', u'26:27-broadcom-wifi']

From this i need to grep the element using keyword as "primary" and return output as

12:13-internet-wifi-primary

i used as follows

                    if (i <= (len(system_info['Ad_List']))):
                        ss = system_info['Ad_List']
                        print type(ss)
                        searchObj = "primary"
                        #if 'primary' in ss:
                        if any(word in searchObj for word in ss):
                            print "inside if"
                            print searchObj
                        else:
                            print "inside else... No search obj"

Always it gets into else part.. :frowning:
How to do it.. split,find are not list attributes

A little more detail (like, i.e. which programming language you use) would be helpful, don't you think?

bakunin

this is python3

From just staring at it - my python doesn't exist - wouldn't it rather be any(searchObj in word ... ?

Try this: (Python 2.7.12 on Ubuntu 16.04 Xenial)

ss = system_info['Ad_List']
searchObj = "primary"
resList = [f for f in ss if searchObj in f]

resList will be a list of one object, or possibly an iterable object in python 3.x

I have just seen your reply to bakunin, and your print statements are python 2, not python 3.

Andrew

=== Edit === Should have been if not where

1 Like

it worked. THanks a lot :slight_smile: