convert output to list(and nested dictionary)

Steven D'Aprano steve at
Wed Jul 22 03:08:13 CEST 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': '', 'proto': 'tcp', 'port': 80}
    d['cidr'] = rule.cidr
    d['proto'] = rule.proto
    d['port'] = rule.port
    return d

and adjust until working.


More information about the Python-list mailing list