pythonpandaslistciscocucm

How do I get a number for each value in my list?


New to Python and programming in general. I'm trying to create a program that will pull device counts from Cisco UCM. Currently, I can get the program to print me out a list of models from CUCM, but ultimately I would like to see how many of each model occurs. For example, if the CUCM server has 5 8845's and 3 8865's, I would like Python to quickly display that information.

Here is my current code:

if __name__ == '__main__':

    resp = service.listPhone(searchCriteria={'name':'SEP%'}, returnedTags={'model': ''})

    model_list = resp['return'].phone
    for phone in model_list:
        print(phone.model)

I've tried to create a DataFrame from Pandas but couldn't get it to work. I think the issue is that I haven't stored the phone.model portion as a variable, but am unable to figure out how to do that.

My goal would be to eventually have an output that reads something like:

8845 - 5
8865 - 3

Thanks in advance for the help!


Solution

  • after playing with CUCM output, i did it like this:

    modellist={}
    for phone in resp['return']["phone"]:
        if phone["model"] in modellist.keys():
            modellist[phone["model"]] += 1
        else:
            modellist[phone["model"]] = 1
    
    
    for phone, count in modellist.items():
        print(phone, " - " ,count)