字典的元素是成键值对出现的,直接对字典使用sorted() 排序,它是根据字典的键的ASCII编码顺序进行排序,要想让字典根据值的大小来排序,可以有两种方法来实现: 一.利用zip函数将字典数据转化为元组再用sorted() 排序 from random import randint # 用随机函数生成待排序的字典数据 my_dict = {x: randint(60, 100) for x in 'abcxyzgkj'} # 将字典数据转化为元组,把字典的值作为元组的第0项,键作为元组的第1项
Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lexicographic