Change sorting order?

Jon Clements joncle at
Fri Jan 22 15:37:19 CET 2010

On Jan 22, 1:58 pm, Gilles Ganault <nos... at> wrote:
> On 22 Jan 2010 13:35:26 GMT, Neil Cerutti <ne... at> wrote:
> >Resorting is more work than is needed. Just choose a different
> >starting index each time you display the names, and set up your
> >lister to wrap-around to your arbitrary starting index.
> Thanks. In this case, it means that in each loop iteration, I must
> search the list to find which item starts with the letter I'd like to
> begin sorting, eg. "B". Does Python include a search method or do I
> have to use a for loop to locate this starting item?

How about a deque of lists... untested

from collections import deque; from itertools import groupby
deq = deque(list(items) for key, items in groupby(sorted(usernames),
lambda L: L[0].upper()))
Then everytime you use deq, rotate it?



More information about the Python-list mailing list