convert output to list(and nested dictionary)

Steven D'Aprano steve at pearwood.info
Tue Jul 21 21:08:13 EDT 2015


On Wed, 22 Jul 2015 07:12 am, max scalf wrote:

> Hello all,
> 
> For Each SecurityGroup, how can i convert that into a List that in turn
> will have a dictionary of the cidr block, protocol type and the port...


Start with this:

def sg_to_list(sg):
    return [rule_to_dict(r) for r in sg.rules]

def rule_to_dict(rule):
    d = {} # expected {'cidr': '0.0.0.0/0', 'proto': 'tcp', 'port': 80}
    d['cidr'] = rule.cidr
    d['proto'] = rule.proto
    d['port'] = rule.port
    return d


and adjust until working.



-- 
Steven




More information about the Python-list mailing list