, :
def helper(x):
global group
if x in group:
return 0, x
return 1, x
def sort_priority(values):
values.sort(key=helper)
numbers = [8, 3, 1, 2, 5, 4, 7, 6]
group = {2, 3, 5, 7}
sort_priority(numbers)
print(numbers)
, sort_priority() , helper, , x.
helper , group - "" (), group, ().
helper :
def helper(x):
global group
if x in group:
return 0, x
return 1, x
, helper key , , , group, , group
[2, 3, 5, 7, 1, 4, 6, 8]
^
The first item that is not in group