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?

From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: how to write a html to automatically display the dictionary?
Date 2014-09-23 19:55 -0400
References <mailman.14262.1411481932.18130.python-list@python.org> <lvsavt$h7m$1@reader1.panix.com> <lvsmkm$kal$2@dont-email.me>
Newsgroups comp.lang.python
Message-ID <mailman.14297.1411516565.18130.python-list@python.org> (permalink)

Show all headers | 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