Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86767
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'properly.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '10:17': 0.16; 'charles': 0.16; 'elem': 0.16; 'looseversion': 0.16; 'mylist': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Sort': 0.16; 'subject:dictionaries': 0.16; 'fix': 0.17; 'thanks,': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'help.': 0.21; 'header:User- Agent:1': 0.23; 'skip:l 30': 0.24; 'sort': 0.25; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'subject:list': 0.30; "i'm": 0.30; 'problem': 0.35; 'skip:u 20': 0.35; 'version': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'highest': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'solve': 0.60; 'new': 0.61; 'numbers': 0.61; "you'll": 0.62; 'show': 0.63; 'name': 0.63; 'charset:windows-1252': 0.65; 'received:12': 0.81; 'have.': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Emile van Sebille <emile@fenx.com> |
| Subject | Re: Sort list of dictionaries |
| Date | Mon, 02 Mar 2015 10:31:59 -0800 |
| References | <f1a339d0-0386-43ba-b6b4-1aee39d75581@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | www.westernstatesglass.com |
| User-Agent | Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
| In-Reply-To | <f1a339d0-0386-43ba-b6b4-1aee39d75581@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| 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.56.1425321135.13471.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425321135 news.xs4all.nl 2836 [2001:888:2000:d::a6]:56252 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86767 |
Show key headers only | View raw
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