sum((float(d['cty']) for d in mpg)) / len(mpg)
output: 16.86
how does the d['cty']) loop through mpg as we are dealing with a list and get value corresponding to it?
[OrderedDict([('', '1'),
          ('manufacturer', 'audi'),
          ('model', 'a4'),
          ('displ', '1.8'),
          ('year', '1999'),
          ('cyl', '4'),
          ('trans', 'auto(l5)'),
          ('drv', 'f'),
          ('cty', '18'),
          ('hwy', '29'),
          ('fl', 'p'),
          ('class', 'compact')]),
OrderedDict([('', '2'),
          ('manufacturer', 'audi'),
          ('model', 'a4'),
          ('displ', '1.8'),
          ('year', '1999'),
          ('cyl', '4'),
          ('trans', 'manual(m5)'),
          ('drv', 'f'),
          ('cty', '21'),
          ('hwy', '29'),
          ('fl', 'p'),
          ('class', 'compact')]),
OrderedDict([('', '3'),
          ('manufacturer', 'audi'),
          ('model', 'a4'),
          ('displ', '2'),
          ('year', '2008'),
          ('cyl', '4'),
          ('trans', 'manual(m6)'),
          ('drv', 'f'),
          ('cty', '20'),
          ('hwy', '31'),
          ('fl', 'p'),
          ('class', 'compact')])]
 
     
     
    