Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-24 Thread Gilles Ganault
On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault nos...@nospam.com wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. display the list from

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-24 Thread Arnaud Delobelle
Gilles Ganault nos...@nospam.com writes: On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault nos...@nospam.com wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-24 Thread Arnaud Delobelle
Arnaud Delobelle arno...@googlemail.com writes: Gilles Ganault nos...@nospam.com writes: On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault nos...@nospam.com wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list

[2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. display the list from

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg.

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault nos...@nospam.com wrote: I see that dictionaries can be sorted using the... sort() method, but is it possible to have Python start sorting from a different letter? Looks like the solution is to read the list of keys into a list, sort the list,

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 13:24:05 +, Steven D'Aprano wrote: On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault wrote: [...] I see that dictionaries can be sorted using the... sort() method, but is it possible to have Python start sorting from a different letter? You can write a customer sort

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
On 2010-01-22, Gilles Ganault nos...@nospam.com wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On 22 Jan 2010 13:35:26 GMT, Neil Cerutti ne...@norwich.edu 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

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 14:09:43 +0100, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Sorry, the code I provided produce this output: ['1a', 'a', 'ac', 'av', 'b', 'c'] ['a', 'ac', 'av', 'b', 'c', '1a'] ['b', 'c', '1a', 'a', 'ac', 'av'] ['c', '1a', 'a', 'ac', 'av', 'b'] ['1a', 'a', 'ac', 'av',

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jan Kaliszewski
22-01-2010 Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg.

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel da...@ieee.org wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's sorted, but starts somewhere

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Arnaud Delobelle
Gilles Ganault nos...@nospam.com writes: On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel da...@ieee.org wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Duncan Booth
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

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jan Kaliszewski
PS. 22-01-2010 o 15:44:28 Jan Kaliszewski z...@chopin.edu.pl wrote: 22-01-2010, 14:58:58 Gilles Ganault nos...@nospam.com wrote: On 22 Jan 2010 13:35:26 GMT, Neil Cerutti ne...@norwich.edu wrote: Resorting is more work than is needed. Just choose a different starting index each time you

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 13:35:26 +, Neil Cerutti wrote: On 2010-01-22, Gilles Ganault nos...@nospam.com wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
On 2010-01-22, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Fri, 22 Jan 2010 13:35:26 +, Neil Cerutti wrote: On 2010-01-22, Gilles Ganault nos...@nospam.com wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Gilles Ganault wrote: On Fri, 22 Jan 2010 14:09:43 +0100, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Sorry, the code I provided produce this output: ['1a', 'a', 'ac', 'av', 'b', 'c'] ['a', 'ac', 'av', 'b', 'c', '1a'] ['b', 'c', '1a', 'a', 'ac', 'av'] ['c', '1a', 'a', 'ac', 'av',

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's sorted, but starts somewhere in the middle,

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Gilles Ganault wrote: On Fri, 22 Jan 2010 14:09:43 +0100, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Sorry, the code I provided produce this output: ['1a', 'a', 'ac', 'av', 'b', 'c'] ['a', 'ac', 'av', 'b', 'c', '1a'] ['b', 'c', '1a', 'a', 'ac', 'av']

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Steven D'Aprano
On Fri, 22 Jan 2010 15:57:07 +, Neil Cerutti wrote: On 2010-01-22, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: Unless you can predict what index to use for (say) names starting with B, then your scheme doesn't work. In order to find that index, you have to do a linear

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Neil Cerutti
On 2010-01-22, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: O(N*Log N) + O(N) == O(N**2)? Oops! :( Of course, the sort is in fast C, and the linear search is in relatively slow Python, so it is quite conceivable that for realistic amounts of data, the time could be dominated

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Gilles Ganault wrote: On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel da...@ieee.org wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
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)

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Gilles Ganault
On Fri, 22 Jan 2010 17:21:02 +0100, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Ok I realized that picking up a random index prevent from grouping names starting with the same letter (to ease visual lookup). Then go for the random char, and use char comparison (my first example). Yup, I

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Dave Angel
Steven D'Aprano wrote: On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: Seems to me the other solutions I've seen so far are more complex than needed. I figure you either want an unordered list, in which case you could use random.shuffle(), or you want a list that's sorted, but starts

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread John Posner
On 1/22/2010 7:17 AM, Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with