Re: converting a set into a sorted list
Thank you for the pointer. I'll upgrade to 2.4. Best, Mack -- http://mail.python.org/mailman/listinfo/python-list
Re: converting a set into a sorted list
On Sat, 14 May 2005 19:20:24 -0700, Robert Kern [EMAIL PROTECTED] wrote: MackS wrote: Dear all, I've got several large sets in my program. After performing several operations on these I wish to present one set to the user [as a list] sorted according to a certain criterion. Is there any direct way to do so? Or must I list = [] for item in set1: list.append(item) list.sort() Can I somehow avoid doing this in two stages? Can I somehow avoid first creating a long list only to immediately sort it afterwards? In Python 2.4, In [1]:sorted? Type: builtin_function_or_method Base Class: type 'builtin_function_or_method' String Form:built-in function sorted Namespace: Python builtin Docstring: sorted(iterable, cmp=None, key=None, reverse=False) -- new sorted list That's plenty of information, but IMO key=None doesn't hint strongly enough about what you can do with it, so I'd advise reading about all the parameters ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
converting a set into a sorted list
Dear all, I've got several large sets in my program. After performing several operations on these I wish to present one set to the user [as a list] sorted according to a certain criterion. Is there any direct way to do so? Or must I list = [] for item in set1: list.append(item) list.sort() Can I somehow avoid doing this in two stages? Can I somehow avoid first creating a long list only to immediately sort it afterwards? Thanks for any guidance, Mack -- http://mail.python.org/mailman/listinfo/python-list
Re: converting a set into a sorted list
MackS wrote: Dear all, I've got several large sets in my program. After performing several operations on these I wish to present one set to the user [as a list] sorted according to a certain criterion. Is there any direct way to do so? Or must I list = [] for item in set1: list.append(item) list.sort() Can I somehow avoid doing this in two stages? Can I somehow avoid first creating a long list only to immediately sort it afterwards? In Python 2.4, In [1]:sorted? Type: builtin_function_or_method Base Class: type 'builtin_function_or_method' String Form:built-in function sorted Namespace: Python builtin Docstring: sorted(iterable, cmp=None, key=None, reverse=False) -- new sorted list -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: converting a set into a sorted list
MackS [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Can I somehow avoid doing this in two stages? Can I somehow avoid first creating a long list only to immediately sort it afterwards? Yes, you could interatively extract and append the min of the set (selection sort), but this would be O(n**2), like bubble or insert sort, instead of the O(n*logn) of make list and sort. You can do the latter in two statements without append: display = list(big_set) display.sort(). As Robert noted, this can be condensed to one using sorted, but that will do the same as the two lines above. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: converting a set into a sorted list
Robert Kern wrote: MackS wrote: Dear all, I've got several large sets in my program. After performing several operations on these I wish to present one set to the user [as a list] sorted according to a certain criterion. Is there any direct way to do so? Or must I list = [] for item in set1: list.append(item) list.sort() So, for this example, just do: sorted(set1) -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list