如何在不使用排序BIF的情况下按密钥插入字典列表?

时间:2016-06-07 02:16:34

标签: python list sorting dictionary

我正在大学学习Python,我有一个我无法弄清楚的练习。我正在编写自己的函数来理解如何在不使用BIF进行排序的情况下对字典进行排序。这是大型练习的一部分,我只需要开始。字典已经在字典列表中。这是我所拥有的,但它不起作用,任何帮助表示赞赏。 牛津是一个字典列表(字典里面有很多数据)

def myInsertion(oxford, key) :
    temp = list() # creating new empty temporary list
    for key in oxford[:-1] : # looking thru all keys in list beginning at end
        temp.append(key) # adding key to temp list
    j = key
    while j < oxford[:-1] :  # comparing j the temp key with last position key
        temp[j] = oxford[j -1] # if true j replaces last position in oxford
        j = j - 1    # to stop continuous looping 

0 个答案:

没有答案
相关问题