Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:a 10': 0.09; '(key,': 0.16; 'pairs,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; "aren't": 0.24; 'received:comcast.net': 0.24; 'skip': 0.24; 'string,': 0.24; 'first,': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'compared': 0.30; 'second,': 0.31; 'tuples': 0.31; 'subject:the': 0.34; 'sequence': 0.36; 'done': 0.36; 'subject:?': 0.36; 'easily': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'first': 0.61; 'more': 0.64; 'as:': 0.81 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: how to write a html to automatically display the dictionary? Date: Tue, 23 Sep 2014 19:55:52 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411516565 news.xs4all.nl 2852 [2001:888:2000:d::a6]:43785 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78261 On 9/23/14 4:53 PM, Denis McMahon wrote: > from string import * You aren't using any names from string, so you can skip this line. > > x={'f1':1,'f2':2,'f3':3} > y = [ (a,x[a]) for a in x.keys() ] > y.sort( cmp=lambda a,b: cmp(a[0],b[0]) ) This is more easily done as: y = sorted(x.items()) .items() returns a sequence of (key, value) pairs, and tuples are sorted lexicographically, so the first elements are compared first, then the second, etc. -- Ned Batchelder, http://nedbatchelder.com