title: How to sort generator type in python
body: <p>My code has below lines</p>
  
  <pre><code>get_alarm_list = conn.query_alarms(query.filter_expr,
                                     query.orderb) 
  print "type is:", type(get_alarm_list)
  for alarm in get_alarm_list:
      if alarm.severity == 'critical':
          alarm.severity = 2
      elif alarm.severity == 'moderate':
          alarm.severity = 1
      else:
          alarm.severity = 0
  
  alarm_list = sorted(get_alarm_list),
                      key=lambda a: a.severity,
                      reverse=True)
  return [alarms.Alarm.from_db_model(alarm)
          for alarm in alarm_list]
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>type is &lt;type 'generator'&gt;
  </code></pre>
  
  <p>The objects in the list are:</p>
  
  <pre><code>for alarm in get_alarm_list:
       print alarm
  
  Output:
  &lt;aodh.storage.models.Alarm object at 0x7fa4c0cb1c50&gt;
  &lt;aodh.storage.models.Alarm object at 0x7fa4c0cb17d0&gt;
  &lt;aodh.storage.models.Alarm object at 0x7fa4c0d86f10&gt;
  &lt;aodh.storage.models.Alarm object at 0x7fa4ca372110&gt;
  &lt;aodh.storage.models.Alarm object at 0x7fa4ca372190&gt;
  &lt;aodh.storage.models.Alarm object at 0x7fa4c0c55d90&gt;
  </code></pre>
  
  <p>And each alarm consists of the below data</p>
  
  <pre><code> {'alarm_actions': [u'log://'], 'ok_actions': [], 'description': u'instance running hot', 'state': u'insufficient data', 'fields': ['alarm_actions', 'ok_actions', 'severity', 'timestamp', 'description', 'time_constraints', 'enabled', 'state_timestamp', 'rule', 'alarm_id', 'state', 'insufficient_data_actions', 'repeat_actions', 'user_id', 'project_id', 'type', 'name'], 'repeat_actions': False, 'enabled': True, 'state_timestamp': datetime.datetime(2016, 5, 27, 6, 41, 5, 987428), 'rule': {u'meter_name': u'cpu_util', u'evaluation_periods': 3, u'period': 600, u'statistic': u'avg', u'threshold': 70.0, u'query': [], u'comparison_operator': u'gt', u'exclude_outliers': False}, 'name': u'ddd', 'alarm_id': u'f5045ed5-5c53-4a6e-be53-23d3368f40c6', 'time_constraints': [], 'insufficient_data_actions': [], 'timestamp': datetime.datetime(2016, 5, 27, 6, 41, 5, 987428), 'user_id': u'9a65b258b5a24e74ac5feae2f6c54229', 'project_id': u'28d1c27e782c4448bf53da00f49d3e1b', 'type': u'threshold', 'severity': 2}
  </code></pre>
  
  <p>How can i iterate over the generator?</p>
  
  <pre><code>alarm_list = sorted(get_alarm_list,
                      key=lambda a: a.severity,
                      reverse=True)
  </code></pre>
  
  <p>But here <code>alarm_list</code> is empty. How can i use sort function on generator <code>get_alarm_list</code></p>