Split-sort-merge

# Split-sort-merge from heapq import merge nums = [34, 12, 15, 64, 32, 27, 8, 15, 22, 24, 9, 20, 4, 17, 8] gods = ['Hermes', 'Ares', 'Cerus', 'Chronos', 'Morpheus', 'Zeus', 'Atlas' , 'Dionysus', 'Eros', 'Kratos', 'Hades', 'Helios', 'Plutus', 'Uranus', 'Poseidon'] for seq in [nums, gods]: split_parts = 5 part_len = len(seq) / split_parts parts = [] for i in range(split_parts): parts.append(seq[i*part_len : (i+1)*part_len]) parts[i].sort() print(parts) # [[12, 15, 34], [27, 32, 64], [8, 15, 22], [9, 20, 24], [4, 8, 17]] # [['Ares', 'Cerus', 'Hermes'], ['Chronos', 'Morpheus', 'Zeus'], ['Atlas', 'Dionysus', 'Eros'], ['Hades', 'Helios', 'Kratos'], ['Plutus', 'Poseidon', 'Uranus']] print(list(merge(*parts))) # [4, 8, 8, 9, 12, 15, 15, 17, 20, 22, 24, 27, 32, 34, 64] # ['Ares', 'Atlas', 'Cerus', 'Chronos', 'Dionysus', 'Eros', 'Hades', 'Helios', 'Hermes', 'Kratos', 'Morpheus', 'Plutus', 'Poseidon', 'Uranus', 'Zeus']