Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Lambda Exact Match

list1 = ['2.2.2.2', '5.5.5.5', '7.7.7.7', '11.11.11.11', '14.14.14.14']


list2 = ['1.1.1.1 cisco asa', '4.4.4.4 cisco 9k', '5.5.5.5 cisco nexus', '9.9.9.9 cisco 7k', '2.2.2.2 cisco 9500', '2.2.2.222 cisco 9300', '14.14.14.14 cisco 9200', '7.7.7.7 cisco 4121', '10.10.10.10 cisco 4100', '11.11.11.11 cisco asr', '100.100.100.100 cisco asr-x', '11.11.111.111 cisco asr-x-2']

########### lambda V3

print "V3"

for tintin in list1:
print filter(lambda a: tintin in a, list2)

OUTPUT

V3

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

['2.2.2.2 cisco 9500', '2.2.2.222 cisco 9300']
['5.5.5.5 cisco nexus']
['7.7.7.7 cisco 4121']
['11.11.11.11 cisco asr']
['14.14.14.14 cisco 9200']

Desired output

Would like to find the exact match… In the first output is giving me 2.2.222 instead of the single 2.2.2.2.

I want to match and compare list1 to list2 and match all the elements in list1 and output only the match in list2. However, I want the exact match. It’s not only matching 2.2.2.2 but is also matching 2.2.2.222 "Dont want to 2.2.2.222".
Thank you

>Solution :

Try to modify the lambda function as follows:

for tintin in list1:
    print(list(filter(lambda a: tintin in a.split(), list2)))

So instead of checking if tintin is a sublist of a, you first get all the words in a (with a.split()) and then you search that list.

Output:

['2.2.2.2 cisco 9500']
['5.5.5.5 cisco nexus']
['7.7.7.7 cisco 4121']
['11.11.11.11 cisco asr']
['14.14.14.14 cisco 9200']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading