Filter List of Network

Solved
eroche
Getting noticed

Filter List of Network

Ok so have my script to grab all our networks. Now I would like to filter that list by a word in the name. This issue I am having is the list of networks is showing the ID and Name together but on separate lines.

 

id: #1

name: #1

id: #2

name: #2

etc...

 

Now I have been able to filter but when I do it only gives new the name and not the id. So if I filter on the name containing Z3:

 

Z3....

Z3.....

etc...

 

I would like it to return id:name combination that matches a word in the name.

 

L_###### : Z3...

 

Here is what I have currently. I have tried a couple different ways of filtering but just can't get it the way I want.

 

import meraki

 

API_KEY = ''

dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)

organization_id = ''

response = dashboard.organizations.getOrganizationNetworks(
organization_id, total_pages='all'
)

 

#ID and Name
fields = ['id', 'name']


for item in response:
     for field in fields:
          if "Z3" in item[field]:
          print (f"{field}: {item[field]}")


Thanks in Advance!

1 Accepted Solution
sungod
Kind of a big deal

You're looping too many times, 'item' has all the elements you want, you just need to select matching 'item's and print the element(s) you want.

 

Something like...

 

for item in response:
    if "Z3" in item["name"]:
        print(f"{item['id']}: {item['name']}")

 

View solution in original post

3 Replies 3
LearningIsFun
Getting noticed

Check out Lambda filter options for the list.  I believe it will do want you need. 

I can share an example later if still needed. 

sungod
Kind of a big deal

You're looping too many times, 'item' has all the elements you want, you just need to select matching 'item's and print the element(s) you want.

 

Something like...

 

for item in response:
    if "Z3" in item["name"]:
        print(f"{item['id']}: {item['name']}")

 

eroche
Getting noticed

That worked thank you...I guess me over thinking a little.

 

Thank you much!

Get notified when there are additional replies to this discussion.