Discuss / Python / 练习

练习

Topic source
L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
def sort_by_name(L=None):
    if L is None:
        L=[]
    L2=[]
    L3=[]
    d={}
    for t in L:
        d[t[0]] = t[1]
        L2.append(t[0])
    print('L2= ',L2)
    print('d= ',d)
    L2 = sorted(L2,key=str.lower)
    print('L2= ', L2)
    for s in L2:
        tmp=(s,d[s])
        L3.append(tmp)
    return L3

  • 1

Reply