Python reorder a sorted list so the highest value is in the middle
问题 I need to reorder a sorted list so the "middle" element is the highest number. The numbers leading up to the middle are incremental, the numbers past the middle are in decreasing order. I have the following working solution, but have a feeling that it can be done simpler: foo = range(7) bar = [n for i, n in enumerate(foo) if n % 2 == len(foo) % 2] bar += [n for n in reversed(foo) if n not in bar] bar [1, 3, 5, 6, 4, 2, 0] 回答1: how about: foo[len(foo)%2::2] + foo[::-2] In [1]: foo = range(7)