user7968
0
Q:

sort list of dictionaries by key python

newlist = sorted(list_to_be_sorted, key=lambda k: k['name']) 
1
# function calling 
def dictionairy():  
  
 # Declaring the hash function       
 key_value ={}     
   
# Initialize value  
 key_value[2] = 56       
 key_value[1] = 2 
 key_value[5] = 12 
 key_value[4] = 24
 key_value[6] = 18      
 key_value[3] = 323 
   
 print ("Task 2:-\nKeys and Values sorted in",  
            "alphabetical order by the key  ")   
  
 # sorted(key_value) returns an iterator over the  
 # Dictionary’s value sorted in keys.   
 for i in sorted (key_value) : 
    print ((i, key_value[i]), end =" ") 
  
def main(): 
    # function calling 
    dictionairy()              
      
# main function calling 
if __name__=="__main__":      
    main() 
0

New to Communities?

Join the community