Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Encapsulation, inheritance and polymorphism

Thread Tools

Re: Encapsulation, inheritance and polymorphism

Arnaud Delobelle
Posts: n/a
On 17 July 2012 13:01, Lipska the Kat <(E-Mail Removed)> wrote:

> 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.
> Please note I am NOT asking for solutions.
> In bash this is laughably trivial

> sort -nr $1 | head -${2:-10}

Here's a Python translation that won't help

from sys import argv
print ''.join(sorted(open(argv[1]), key=lambda l:
-int(l.split('\t')[0]))[:10 if len(argv) < 3 else int(argv[2])])

Who said Python was readabl'y yours,

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Class Variables, Inheritance, and Polymorphism crjjrc C++ 8 04-05-2007 08:39 PM
Dynamic polymorphism vs. Static polymorphism Krivenok Dmitry C++ 13 06-01-2006 09:49 AM
I need help with "Inheritance" and "Polymorphism" Fao C++ 13 05-01-2006 11:55 PM
Inheritance, polymorphism, and introspection in Python combinational.logic $ Python 0 05-27-2005 05:36 PM
trying to understand Inheritance, Polymorphism and templates sapropel C++ 1 05-14-2004 02:25 PM