sorting - sort by actual values in a dictionary python -


मुझे सॉर्टिंग डिक्शनरी में परेशानी हो रही है

  sorted_x = sorted (x.iteritems (), key = operator.itemgetter (1))   

लेकिन मुझे सॉर्ट करने के लिए नीचे कोड का उपयोग कर रहा हूं समस्या यह है कि वास्तविक मानों से ऐसा नहीं किया जाता है ..

  asdl 1 testin 42345 अल्फा 49   

रेफ़री:

I एस्सारएल अल्फ़ा 49 टेस्टिन 42345

आप जिस व्यवहार का अनुभव कर रहे हैं वह तुलनात्मक चर के प्रकार के कारण है इसे हल करने के लिए, इसे पूर्णांक पर डालें।

  orted (x.iteritems (), कुंजी = लैम्ब्डा x: int (x [1])) < / कोड>  

अंतिम परिणाम होगा:

  [('asdl', '1'), ('अल्फा', '49'), ('testin ',' 42345 ')]    

Comments

Popular posts from this blog

sql - Postgresql record to array -

c++ - Cmake produces file extensions in static library archives -

java - Clearing application data programatically android -