On 22 Jan 2010 15:24:58 GMT, Duncan Booth <duncan.bo...@invalid.invalid> wrote: >Here's another:
Thanks for the sample. It work great, except that it also runs when the header character doesn't match any item in the list: ======= import bisect connected = [] connected.append("_test") connected.append("-test") connected.append("0test") connected.append("1test") connected.append("Aa") connected.append("Bb") connected.append("Cc") def rotated_sort(data, startch): data = sorted(data) pos = bisect.bisect_left(data, startch) return data[pos:] + data[:pos] for ch in "_-0123456789ABCDEFGHIJKLMNOPQRSTUVWYZ": print ch, rotated_sort(connected, ch) ======= C:\>test.py _ ['_test', '-test', '0test', '1test', 'Aa', 'Bb', 'Cc'] - ['-test', '0test', '1test', 'Aa', 'Bb', 'Cc', '_test'] 0 ['0test', '1test', 'Aa', 'Bb', 'Cc', '_test', '-test'] 1 ['1test', 'Aa', 'Bb', 'Cc', '_test', '-test', '0test'] 2 ['Aa', 'Bb', 'Cc', '_test', '-test', '0test', '1test'] 3 ['Aa', 'Bb', 'Cc', '_test', '-test', '0test', '1test'] 4 ['Aa', 'Bb', 'Cc', '_test', '-test', '0test', '1test'] ======= Should I add an "if" block in the "for ch in"? -- http://mail.python.org/mailman/listinfo/python-list