Jean-Michel Pichavant <jeanmic...@sequans.com> wrote: > Here is one possible solution > > l = ['1a', 'a', 'b','c','av','ac'] # you mentioned a dictionary in your > post, if so, l = myDict.keys() > l.sort() # sort your list once and for all > for start in '1abcd': > result = [name for name in l if name[0] >= start] + [name for name > in l if name[0] < start] > print result
Here's another: >>> import bisect >>> def rotated_sort(data, startch): data = sorted(data) pos = bisect.bisect_left(data, startch) return data[pos:] + data[:pos] >>> for ch in " 1abcd": print ch, rotated_sort(['1a', 'a', 'b','c','av','ac'], ch) ['1a', 'a', 'ac', 'av', 'b', 'c'] 1 ['1a', 'a', 'ac', 'av', 'b', 'c'] a ['a', 'ac', 'av', 'b', 'c', '1a'] b ['b', 'c', '1a', 'a', 'ac', 'av'] c ['c', '1a', 'a', 'ac', 'av', 'b'] d ['1a', 'a', 'ac', 'av', 'b', 'c'] >>> -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list