Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78261

Re: how to write a html to automatically display the dictionary?

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 <python-python-list@m.gmane.org>
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 <ned@nedbatchelder.com>
Subject Re: how to write a html to automatically display the dictionary?
Date Tue, 23 Sep 2014 19:55:52 -0400
References <mailman.14262.1411481932.18130.python-list@python.org> <lvsavt$h7m$1@reader1.panix.com> <lvsmkm$kal$2@dont-email.me>
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 <lvsmkm$kal$2@dont-email.me>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14297.1411516565.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

how to write a html to automatically display  the dictionary? luofeiyu <elearn2014@gmail.com> - 2014-09-23 22:18 +0800
  Re: how to write a html to automatically display  the dictionary? Tobiah <toby@tobiah.org> - 2014-09-23 09:53 -0700
    Re: how to write a html to automatically display  the dictionary? Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-23 20:20 +0000
  Re: how to write a html to automatically display the dictionary? John Gordon <gordon@panix.com> - 2014-09-23 17:34 +0000
    Re: how to write a html to automatically display the dictionary? Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-23 20:53 +0000
      Re: how to write a html to automatically display the dictionary? Ned Batchelder <ned@nedbatchelder.com> - 2014-09-23 19:55 -0400

csiph-web