Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'bash': 0.07; 'item.': 0.07; 'ok.': 0.07; 'python': 0.09; '"r"': 0.09; 'tab': 0.09; 'terry': 0.09; '"n"': 0.16; '2.7.3': 0.16; 'ascending': 0.16; 'commandline': 0.16; 'descending': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'numerically': 0.16; 'outputs': 0.16; 'reedy': 0.16; 'task.': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'followed': 0.20; 'sort': 0.21; 'solutions.': 0.23; "i've": 0.23; 'linux': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'leave': 0.26; 'am,': 0.27; 'order.': 0.27; 'is?': 0.27; 'options': 0.27; 'received:192.168.1.3': 0.29; 'code': 0.31; 'asking': 0.32; 'implement': 0.32; 'problem.': 0.32; 'file': 0.32; 'could': 0.32; 'ubuntu': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'done': 0.34; 'list': 0.35; "won't": 0.35; 'something': 0.35; 'but': 0.36; 'compare': 0.36; 'stock': 0.36; 'subject:: ': 0.38; 'brief': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'easy': 0.60; 'subject:, ': 0.61; 'containing': 0.61; 'more.': 0.62; 'taking': 0.65; 'reverse': 0.65; 'header:Reply-To:1': 0.68; 'believe': 0.69; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:python.org': 0.84; 'inefficient': 0.91; 'kat': 0.91; 'subject:skip:E 10': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=aJVyWMBm c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=YsUzL_8ObRgA:10 a=wlnPGDZH2tUA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=5aXqyK1oV-WnSIQaj0MA:9 a=wPNLvfGTeEIA:10 a=ZromQyecwmchonBO:21 a=6BSaWSMvNwAoDCva:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Tue, 17 Jul 2012 18:43:02 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Encapsulation, inheritance and polymorphism References: <3-WdnYTg0r6XyZjNnZ2dnUVZ7sidnZ2d@bt.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342546982 news.xs4all.nl 6911 [2001:888:2000:d::a6]:34007 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25520 On 17/07/2012 18:24, Terry Reedy wrote: > On 7/17/2012 8:01 AM, Lipska the Kat wrote: >> On 17/07/12 09:45, Lipska the Kat wrote: >>> Pythoners >>> >>> Python 2.7.3 >>> Ubuntu Linux 12.04 LTS >>> >>> I've been taking a brief look at Python. >>> >> >> snip >> >> Well I've set myself a task. >> I have a text file containing a list of stock items >> each line contains the number in stock followed by a tab followed by the >> name of the item. I need to implement something that reads in the text >> file and outputs the stock list in ascending or descending order of >> quantity. > > Nice problem. Easy but non-trivial. > >> Please note I am NOT asking for solutions. > > Ok. With some inefficient redundancy, I believe it could be done in one > line in Python. Better code would take a few more. > >> In bash this is laughably trivial >> >> sort -nr $1 | head -${2:-10} > > Won't sort work alphabetically and leave the following as is? > > 1\talpha > 11\tbeta > 2\tgamma > The commandline options are "-nr". "n" means compare numerically and "r" means reverse order.