python sorting deep in objects -


i need sorting in python. got data object, in objects lists , sort data specific list item. print out this:

 item in data:      proj in item:          print proj.get('id') 

so want data sorted 'id' item.

this how data object looks like, if print it:

[[{u'archived': false, u'name': u'someone', u'num_files': 0, u'managed_by': {u'username': u'somebody', u'role': u'somerole', u'email_address': u'me@somewhere', u'id': u'307', u'name': u'firstname lastname'}, u'updated_on': u'2015-06-18 17:55:39', u'id': 23},  {u'archived': false, u'name': u'someoneelse', u'num_files': 0, u'managed_by': {u'username': u'somebody else', u'role': u'somerole', u'email_address': u'you@somewhere', u'id': u'341', u'name': u'firstname lastname'}, u'updated_on': u'2015-06-09 17:38:52', u'id': 48}]] 

just 2 lists whole, sort last id, in example 23 , 48

try this:

import numpy np data_new = np.array(data).flatten() sorted_list = sorted(data_new, key=lambda x: x['id']) 

first line create 1 list of dict. second sort them 'id' key. after print want:

for in sorted_list:     print(i['id']) 

edit: because list contain sublists of different sizes (like here) broke ndarray.flatten or numpy.ravel, because elements dictionaries np.fromiter unworkable too. should change second line this:

data_new = np.hstack(data) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -