import timeit
timeit.timeit(stmt="a = '_'.join(sorted([str(x) for x in n]))", setup=
    'import random; n = [random.randint(0,1000) for i in range(100)]')
timeit.timeit(stmt="a = '_'.join(sorted(str(x) for x in n))", setup=
    'import random; n = [random.randint(0,1000) for i in range(100)]')
Python: цикл for в назначении индекса