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

c# - The item with identity 'Id' already exists in the metadata collection. Parameter name: item -

sql - PostgreSQL automatically update row at specific date -

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