daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [
  2.     {
  3.         'flight_id': 'f123',
  4.         'pax': 234,
  5.         'airline': 'Foo Airways'
  6.     },
  7.     {
  8.         'flight_id': 'f124',
  9.         'pax': 200,
  10.         'airline': 'Bar Airways'
  11.     }
  12. ]
  13.    
  14. {
  15.     'f123': {'pax': 234, 'airline': 'Foo Airways'},
  16.     'f124': {'pax': 200, 'airline': 'Bar Airways'}
  17. }
  18.    
  19. flights = dict((f.pop('flight_id'), f) for f in flights)
  20.    
  21. flights = {f.pop('flight_id'): f for f in flights}
  22.    
  23. >>> d = [
  24. ...     {
  25. ...         'flight_id': 'f123',
  26. ...         'pax': 234,
  27. ...         'airline': 'Foo Airways'
  28. ...     },
  29. ...     {
  30. ...         'flight_id': 'f124',
  31. ...         'pax': 200,
  32. ...         'airline': 'Bar Airways'
  33. ...     }
  34. ... ]
  35. >>> itms = [x.pop('flight_id') for x in d]
  36. >>> dict(zip(itms,d))
  37. {'f124': {'pax': 200, 'airline': 'Bar Airways'}, 'f123': {'pax': 234, 'airline':
  38.  'Foo Airways'}}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top