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

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

Installing croogo for cakephp -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -