473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

list.sort(): heaviest item?

If I have a list of items of mixed type, can I put something into it
such that after a list.sort(), is guaranteed to be at the end of the
list?

Looking at http://www.python.org/doc/2.3.5/ref/comparisons.html
"Most other types compare unequal unless they are the same object; the
choice whether one object is considered smaller or larger than another
one is made arbitrarily but consistently within one execution of a
program."

makes me unsure.

It looks like "None" always ends up at the start ("lightest"), but I
want the opposite ("heaviest").

-Steven
Apr 8 '08 #1
1 1336
On Apr 8, 8:15*am, "Steven Clark" <steven.p.cl...@gmail.comwrote:
If I have a list of items of mixed type, can I put something into it
such that after a list.sort(), is guaranteed to be at the end of the
list?
Since the other guys gave you the real answer, how about this:

sentinel = object()
mylist.sort()
mylist.append(sentinel)

_ ~
@ @
\_/

Apr 8 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Derek Basch | last post by:
Hello All, I need to sort a list using an unnatural sequence. I have a list like so: foo = print foo.sort()
5
by: Valkyrie | last post by:
I have a list of tuples, and one of the fields in the tuple is score. So how can I sort the list by the score? Thanks in advance
4
by: Seeker | last post by:
Hi, I have an array of objects. My object definition is given below: function tempArray(code,height,weight) { this.code = code; this.height = height; this.weight = weight; }
18
by: Doug Bell | last post by:
Hi, I have a function that loads Rows from a field in a DataTable into an ArrayList. See below: It also adds a Row (eg "All Areas"). I wanted this new row to be the first record so I added a...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
4
by: shrishjain | last post by:
Hi All, I need a type where I can store my items in sorted order. And I want to keep adding items to it, and want it to remain sorted. Is there any type in .net which I can make use of. I see...
6
by: Julia | last post by:
I am trying to sort a linked list using insertion sort. I have seen a lot of ways to get around this problem but no time-efficient and space-efficient solution. This is what I have so far: ...
6
by: Nick Valeontis | last post by:
I know how to use Icomparable. However, I can't figure out how to sort a generic linked list? (without writing the algorithm) Lets say I have something like this: class...
6
by: Tekkaman | last post by:
I have a list of lists and I want to define an iterator (let's call that uniter) over all unique elements, in any order. For example, calling: sorted(uniter(, , ])) must return . I tried the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.