#!/usr/bin/python3 # -*- coding: utf-8 -*- """ Sorting all kinds of containers .sort() sorts in place sorted() produces new sorted(listobject, key=whatever) where whatever is a function to apply to each list element before sorting """ my_list = [[25], [15, 25, 35], [10, 15]] # Without modifying sorted_list = sorted(my_list, key=max) print("Sorted list:", sorted_list) # Without modifying my_list.sort() print("Sorted list:", my_list) # TODO dict sorting better. # sorting dicts (by key) (TODO, this is value currently) # sorted_by_value = sorted(phonebook, key=char_dict.get, reverse=True) # sorted_by_value = sorted(phonebook.items(), key=lambda item: item[1], reverse=True) # sorted_by_value = sorted(phonebook, key=char_dict.__getitem__, reverse=True) # sorting dicts (by value) (TODO) # sorted_by_value = sorted(phonebook, key=char_dict.get, reverse=True) # sorted_by_value = sorted(phonebook.items(), key=lambda item: item[1], reverse=True) # sorted_by_value = sorted(phonebook, key=char_dict.__getitem__, reverse=True)