View Single Post
Old 07-04-2015, 04:37 PM   #18
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,682
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by rubeus View Post
Why is

Code:
        image['values'] = img_dic.keys().sort()
exporting an empty list?
The sort() method of a list modifies the list in place, but returns None. To do what you want with the list method, you'd have to do something like:

Code:
image['values'] = img_dic.keys()
image['values'].sort()
print image['values']
The 'sort' list method was all that was available prior to Python 2.4. The builtin function 'sorted' (available from Python 2.4+) builds a new sorted list from any iterable--and is imminently handier most times--as you've no doubt discovered.

Code:
print sorted(img_dic.keys())

Last edited by DiapDealer; 07-05-2015 at 12:46 PM.
DiapDealer is offline   Reply With Quote