Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:object': 0.07; 'object?': 0.09; 'called,': 0.16; 'generated,': 0.16; 'lambda': 0.16; 'subject:sort': 0.16; 'tmp': 0.16; 'subject:list': 0.16; 'convert': 0.19; 'default,': 0.23; 'code': 0.24; 'changed': 0.25; 'all,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'hash': 0.30; 'subject:?': 0.31; 'print': 0.32; 'source': 0.32; 'list': 0.32; 'to:addr:python-list': 0.34; 'do?': 0.35; 'subject:new': 0.36; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'order': 0.62; 'increase': 0.64; 'order,': 0.73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=ZNYnJDTic+S1/koXnYLPkZ1BLzOTFGOctSVht82la78=; b=D10BIIm+JyBYuoh0hXfTSqYu92vgR+5bny444vw5gLJ3x32YQtMNcbloTMronoZxkG KiUFmCZP8ZTGLafB6Q3tpaHv9ugRm9kxSGCoBGP6F+ufdNnxwxy6EXCtrgaRSzAqi9U2 XFD0McOlyREic7pIWqJDLM/cDLZ3abiouU3JU= MIME-Version: 1.0 Date: Wed, 3 Aug 2011 02:02:09 +0800 Subject: how to sort a hash list without generating a new object? From: smith jack To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312308133 news.xs4all.nl 23939 [2001:888:2000:d::a6]:37993 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10753 the source code is as follows x={} x['a'] = 11 x['c'] = 19 x['b'] = 13 print x tmp = sorted(x.items(), key = lambda x:x[0]) # increase order by default, if i want to have a descending order, what should i do? # after sorted is called, a list will be generated, and the hash list x is not changed at all, how to convert x to a sorted hash list without generating a new object? print tmp print x