Encapsulation, inheritance and polymorphism

Arnaud Delobelle arnodel at gmail.com
Wed Jul 18 06:35:51 EDT 2012


On 17 July 2012 13:01, Lipska the Kat <lipska at lipskathekat.com> 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,

-- 
Arnaud



More information about the Python-list mailing list