MCPcopy Create free account
hub / github.com/geekcomputers/Python / mixed_sorting

Function mixed_sorting

game_of_life/05_mixed_sorting.py:28–56  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

26
27
28def mixed_sorting(nums):
29 positions = []
30 odd = []
31 even = []
32 sorted_list = []
33 for i in nums:
34 if i % 2 == 0:
35 even.append(i)
36 positions.append("E")
37 else:
38 odd.append(i)
39 positions.append("O")
40 even.sort()
41 odd.sort()
42 odd.reverse()
43 j, k = 0, 0
44 for i in range(len(nums)):
45 if positions[i] == "E":
46 while j < len(even):
47 sorted_list.append(even[j])
48 j += 1
49 break
50 else:
51 while k < len(odd):
52 sorted_list.append(odd[k])
53 k += 1
54 break
55
56 return sorted_list
57
58
59# DO NOT TOUCH THE BELOW CODE

Callers 2

test_1Method · 0.85
test_2Method · 0.85

Calls 2

appendMethod · 0.45
reverseMethod · 0.45

Tested by 2

test_1Method · 0.68
test_2Method · 0.68