Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'string': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'dotted': 0.16; 'sorting': 0.16; 'subject:Sort': 0.16; 'subject:dictionaries': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'trying': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'probably': 0.32; 'entirely': 0.33; 'info': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'false': 0.36; 'module.': 0.36; 'should': 0.36; 'little': 0.38; 'numbers': 0.61; 'simple': 0.61; '3.4': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=DHOIoNVjb+dhIucg4hBCj2Pj1jQ5YK92VSLAEnK+/bQ=; b=jNxhZWXpQP/oVq4QHgvvh6onhW/x1i64DpTGtf3TZUbGfMtJmCt82BfSlFkfM9zLr+ y6d89A3Ch7Nd9qlGpXhSAWPwlbMadBTbPb3niWgLrwtH5vdakCNIAMi4DRQTaAVLEXZt IonneTh6jZMHJikJYb3WiopR6ufP0koGg4vWg9qaKGJj3m/dWVV7gas4mXwU18jRwprf 48qHJe4QdXf5wGEJA5eXD9cohQfocX+ZUAQAlM9GMmADwxPXS8nB8lLVn0PHhQyeV8Y5 X/n0Cvp1faW44Vq3/OuDW9ZD6PnEKhD9c1oSCQxG7fOqFLtsV2BEroNHRe8/WGEXyOWz SL1w== MIME-Version: 1.0 X-Received: by 10.180.90.237 with SMTP id bz13mr42296802wib.45.1425360815327; Mon, 02 Mar 2015 21:33:35 -0800 (PST) In-Reply-To: References: <946797be-10e6-433b-9411-2db0d5697ac8@googlegroups.com> Date: Mon, 2 Mar 2015 22:33:35 -0700 Subject: Re: Sort list of dictionaries From: Jason Friedman Cc: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425360823 news.xs4all.nl 2943 [2001:888:2000:d::a6]:39985 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86813 >> This is what I was trying but LooseVersion() was not sorting version numbers like I thought it would. You will notice that Chrome version "40.0.2214.111" is higher than "40.0.2214.91" but in the end result it's not sorting it that way. > > Because it's a string they're sorted lexicographically, and in that > ordering "40.0.2214.111" is less than "40.0.2214.91". Instead of a > string you should probably use some sort of version info tuple. A > simple tuple of ints may suffice, although you may need to get a > little cleverer if there are ever any version strings that aren't > entirely dotted numeric. Also, Python 3.4 comes with an ipaddress module. >>> import ipaddress >>> address_string_1 = "2.2.3.4" >>> address_string_2 = "10.2.3.4" >>> address_string_2 > address_string_1 False >>> ip_address_1 = ipaddress.ip_address(address_string_1) >>> ip_address_2 = ipaddress.ip_address(address_string_2) >>> ip_address_2 > ip_address_1 True