I have a list of object that looks like this.  hand = [ Card(10, 'H'), Card(2,'h'), Card(12,'h'), Card(13, 'h'), Card(14, 'h') ]   Card(10, 'H) here is not a tuple, but an object. I know how to sort this list if each item in the list was in a form of tuple, like this,  hand = sorted(hand, key = lambda x: x[0])   but I have no idea how to sort a list of objects. I want to sort my list by the first input value, which is the number in Card()  How can I do this?   Edit: Here's the definition of Card().  class Card(object):      RANKS = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)      SUITS = ('C', 'D', 'H', 'S')      def __init__(self, rank=12, suit='S'):          if (rank in Card.RANKS):             self.rank = rank         else:             self.rank = 12          if (suit in Card.SUITS):             self.suit = suit.upper()         else:             self.suit = 'S'      def __str__(self):         if (self.rank == 14):             rank = 'A'         elif (self.rank == 13):             rank = 'K'         elif (self.rank == 12):             rank = 'Q'         elif (self.rank == 11):             rank = 'J'         else:             rank = str(self.rank)         return rank + self.suit      def __eq__(self, other):         return (self.rank == other.rank)      def __ne__(self, other):         return (self.rank != other.rank)      def __lt__(self, other):         return (self.rank &lt; other.rank)      def __le__(self, other):         return (self.rank &lt;= other.rank)      def __gt__(self, other):         return (self.rank &gt; other.rank)      def __ge__(self, other):         return (self.rank &gt;= other.rank)
I've got a list of Python objects that I'd like to sort by an attribute of the objects themselves.  The list looks like:  &gt;&gt;&gt; ut [&lt;Tag: 128&gt;, &lt;Tag: 2008&gt;, &lt;Tag: &lt;&gt;, &lt;Tag: actionscript&gt;, &lt;Tag: addresses&gt;,  &lt;Tag: aes&gt;, &lt;Tag: ajax&gt; ...]   Each object has a count:  &gt;&gt;&gt; ut[1].count 1L   I need to sort the list by number of counts descending.  I've seen several methods for this, but I'm looking for best practice in Python.
How to set up USB for Virtualbox? I'm using Ubuntu Maverick and Virtual Box 3+. I have Windows 7 Ultimate. The problem is that it doesn't detect USB drives in Windows 7, but USB peripherals (mouse + keybord) are working.  I followed , but I can't find the user group vboxusers. How can I continue? I would also like to upgrade to the latest version without any risk (without losing my virtual hard disk drive). Is it ethical to use a recommendation letter from a deceased professor? She was a really nice professor and she wrote me a good recommendation letter that resulted in a lot of good results with applications. Recently, this professor died from brain cancer, which was a fast and shocking death for me.  Tomorrow is the deadline for a grant. What should I do? Is it professional to use letters from the deceased? Let n be an even integer. How many different ways can I choose subsets of the set {1,2...,n} List of apps ever downloaded Should a "thank you" comment, for instance Thanks for your answer, be flagged as non-constructive?  If a "thank you" comment is flagged as non-constructive what would the moderator reaction to this flag be? Would it be marked as helpful, or not? Identification of particles and anti-particles The identification of an electron as a particle and the positron as an antiparticle is a matter of convention. We see lots of electrons around us so they become the normal particle and the rare and unusual positrons become the .  My question is, when you have made the choice of the electron and positron as particle and anti-particle does this automatically identify every other particle (every other fermion?) as normal or anti?  For example the proton is a particle, or rather the quarks inside are. By considering the interactions of an electron with a quark inside a proton can we find something, e.g. a conserved quantity, that naturally identifies that quark as a particle rather than an antiparticle? Or do we also just have to extend our convention so say that a proton is a particle rather than an antiparticle? To complete the family I guess the same question would apply to the neutrinos. Let $X$ be a random variable and let $g,f$ be real-valued, nondecreasing, and bounded.   Show that $\mathbb{E}[f(X)g(X)]\geq \mathbb{E}[f(X)]\mathbb{E}[g(X)]$  Having a hard time seeing where to start for some reasons, any hints?  I managed to write:  $\mathbb{E}[f(X)g(X)] = \frac{1}{4}\mathbb{E}[(f(X)+g(X))^2 - (f(X)-g(X))^2]$  But I'm not sure if this is in the right direction or not. What is the difference between conditioning on regressors vs. treating them as fixed? Why does chmod 777 -R / leave the system unusable? Why can't we see infrared light? Looking around for rim brake pads, I have noticed a wide variety:   low end-ish: cheap, rubber pad with metal stem, unknown brand high end-ish: expensive, rubber pad with metal stem, known brand cool end-ish: dedicate pad sections (1 for dry, 1 for mud, 1 for rain)   Is there any good reason to go for an high end-ish or for the cool end-ish, or is it just plain old marketing tricks? Define additional math operators to be typeset in roman Mathematical operators, such as function names, should be set in roman type, not italics. Latex already has commands for some operators, including \max, \min, and \log.  How can I define additional such commands? How are Python's Built In Dictionaries Implemented? Does anyone know how the built in dictionary type for python is implemented?  My understanding is that it is some sort of hash table, but I haven't been able to find any sort of definitive answer. Are undead and creatures immune to charm excluded from the HP count of Sleep? From the spell description:     Sleep (...) Creatures within 20 feet of a point you choose within range are affected in ascending order of their current hit points (ignoring unconscious creatures). Starting with the creature that has the lowest current hit points,(...) Subtract each creature’s hit points from the total before moving on to the creature with the next lowest hit points. A creature’s hit points must be equal to or less than the remaining total for that creature   to be affected. Undead and creatures immune to being charmed aren’t affected by this spell. (PH p.276)   Now, to build the ascending order of their current hitpoints, the spell instructs to count everyone in area of effect, but only ignore unconscous creatures. Then later on it says that Undead and creatures immune to being charmed aren't affected.  Are those two latter kinds of creatures excluded from the roll of current HP by default? Following the "if they were it would say so" philosophy of Sage Advice, it doesn't seem so to me. How to validate an email address using a regular expression? What is the LaTeX command for "em dash" (—)? I am trying to insert the symbol in the title of the question, which I copied from a PDF article, but it appears as space in the output file. What is the corresponding LaTeX command? How can metagaming retries on poor skill checks be prevented? I'm sure every DM has had this happen: one PC is trying to find something cool on a dead monster's body. The player rolls poorly, and instead of accepting the paltry 2 copper pieces, the PC calls all the party members over to also try looting the corpse. Invariably, a different player rolls well, and everyone walks away satisfied that everything's been taken down to the poor dead monster's last holey sock.   Another example: One PC is trying to find some useful information in a library. There're no guards, no reason anyone would be bothered, and no time restraints to stress about. The player rolls poorly, so all the other PCs try, too.  I'd describe this as well-intentioned metagaming. The players are afraid of losing out on content, this despite multiple sessions of me making it clear that I don't structure my games to penalize gameplay that way.  These are situations that require a roll to determine the degree of success. (At least I think so; perhaps I'm wrong here?) Failure could set back the PCs a cool item or a bit of information that would have helped a little, but these minor failures aren't game-enders or anything. As a DM I can't see a reason to say "No" and disallow the practice, but it feels vaguely like cheating to let the players roll multiple times to get better results.  How do I prevent players ganging up on skill checks after they've seen someone roll poorly? Where's the energy in a boosted capacitor? Suppose I look at a parallel plate capacitor in its rest frame and calculate the electrostatic energy, $E$.  Next, I look at the same capacitor in a primed frame boosted in the direction perpendicular to the plane of the plates. In this frame, the $E$-field is the same strength, there is no magnetic field, and the volume over which the $E$-field extends is less by a factor $1/\gamma$. This suggests $E' = \frac{1}{\gamma} E$, but relativity states that energy transforms as $E' = \gamma E$.   Where is the missing energy? What is a nicer, less immature saying?  I love using 'A Freudian slip', but that is only applicable in certain situations. Is it possible to make an ASP.NET MVC route based on a subdomain? Is it possible to have an ASP.NET MVC route that uses subdomain information to determine its route?  For example:   user1.domain.com goes to one place user2.domain.com goes to another?   Or, can I make it so both of these go to the same controller/action with a username parameter?