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

asp.net - Procedure or function "Procedure name" expects a parameter "Param name" which was not supplied occurs rarely -

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -

sql server ce - Is there some way to make sqlce3.5 and 4.0 co-exist in the C# project -