Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86767
| From | Emile van Sebille <emile@fenx.com> |
|---|---|
| Subject | Re: Sort list of dictionaries |
| Date | 2015-03-02 10:31 -0800 |
| References | <f1a339d0-0386-43ba-b6b4-1aee39d75581@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.56.1425321135.13471.python-list@python.org> (permalink) |
On 3/2/2015 10:17 AM, Charles Heizer wrote:
> Hello,
> I'm new to python and I'm trying to find the right way to solve this issue I have.
>
> I'm trying to sort this list by name and then by version numbers. The problem I'm having is that I can not get the version numbers sorted with the highest at the top or sorted properly.
>
> mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'},
> {'name': u'com.google.earth', 'version': u'7.1.2.2019'},
> {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'},
> {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'},
> {'name': u'com.google.Chrome', 'version': u'40.0.2214.111'},
> {'name': u'com.google.Chrome', 'version': u'39.0.2171.99'},
> {'name': u'com.google.Chrome', 'version': u'39.0.2171.95'},
> {'name': u'com.google.Chrome', 'version': u'39.0.2171.71'},
> {'name': u'com.google.Chrome', 'version': u'38.0.2125.122'},
> {'name': u'com.google.Chrome', 'version': u'38.0.2125.111'},
> {'name': u'com.google.Chrome', 'version': u'38.0.2125.104'},
> {'name': u'com.google.Chrome', 'version': u'38.0.2125.101'},
> {'name': u'com.google.Chrome', 'version': u'37.0.2062.94'},
> {'name': u'com.google.Chrome', 'version': u'37.0.2062.120'},
> {'name': u'com.google.Chrome', 'version': u'36.0.1985.143'},
> {'name': u'com.google.Chrome', 'version': u'36.0.1985.125'},
> {'name': u'com.google.Chrome', 'version': u'35.0.1916.153'},
> {'name': u'com.google.Chrome', 'version': u'35.0.1916.114'},
> {'name': u'com.google.Chrome', 'version': u'34.0.1847.137'},
> {'name': u'com.google.Chrome', 'version': u'34.0.1847.131'},
> {'name': u'com.google.Chrome', 'version': u'34.0.1847.116'},
> {'name': u'com.google.Chrome', 'version': u'33.0.1750.152'},
> {'name': u'com.google.Chrome', 'version': u'33.0.1750.149'},
> {'name': u'com.google.Chrome', 'version': u'33.0.1750.146'},
> {'name': u'com.google.Chrome', 'version': u'32.0.1700.107'},
> {'name': u'com.google.Chrome', 'version': u'31.0.1650.63'},
> {'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}]
>
> sortedlist = sorted(mylist , key=lambda x, y: x['name'] LooseVersion(elem['version'])), reverse=True)
You'll need to fix LooseVersion or elem or both -- or show them so we
can help.
Emile
>
> Thanks,
> Charlie
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Sort list of dictionaries Charles Heizer <ceh329@gmail.com> - 2015-03-02 10:17 -0800
Re: Sort list of dictionaries Emile van Sebille <emile@fenx.com> - 2015-03-02 10:31 -0800
Re: Sort list of dictionaries Charles Heizer <ceh329@gmail.com> - 2015-03-02 10:38 -0800
Re: Sort list of dictionaries Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-02 11:55 -0700
Re: Sort list of dictionaries Charles Heizer <ceh329@gmail.com> - 2015-03-02 10:58 -0800
Re: Sort list of dictionaries Peter Otten <__peter__@web.de> - 2015-03-02 20:23 +0100
Re: Sort list of dictionaries Charles Heizer <ceh329@gmail.com> - 2015-03-03 07:56 -0800
Re: Sort list of dictionaries Chris Angelico <rosuav@gmail.com> - 2015-03-04 03:09 +1100
Re: Sort list of dictionaries Paul Moore <p.f.moore@gmail.com> - 2015-03-03 08:48 -0800
Re: Sort list of dictionaries Peter Otten <__peter__@web.de> - 2015-03-03 18:44 +0100
Re: Sort list of dictionaries Dave Angel <davea@davea.name> - 2015-03-02 13:59 -0500
Re: Sort list of dictionaries Jason Friedman <jsf80238@gmail.com> - 2015-03-02 22:33 -0700
Re: Sort list of dictionaries Chris Angelico <rosuav@gmail.com> - 2015-03-03 18:07 +1100
Re: Sort list of dictionaries Jason Friedman <jsf80238@gmail.com> - 2015-03-03 07:45 -0700
Re: Sort list of dictionaries Chris Angelico <rosuav@gmail.com> - 2015-03-04 01:50 +1100
Re: Sort list of dictionaries Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 18:55 +1100
csiph-web