Discuss / Python / sorted作业

sorted作业

Topic source

星辰德法

#1 Created at ... [Delete] [Delete and Lock User]

# sorted 作业1

'''

# -*- coding: utf-8 -*-

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_name(t):

    return t[0].lower()

L2 = sorted(L, key=by_name)

print(L2)

'''

'''

# sorted 作业2

# -*- coding: utf-8 -*-

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_score(t):

    return -t[1]

L2 = sorted(L, key=by_score)

print(L2)

'''


  • 1

Reply