Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Encapsulation, inheritance and polymorphism (http://www.velocityreviews.com/forums/t948197-re-encapsulation-inheritance-and-polymorphism.html)

Tim Chase 07-17-2012 05:56 PM

Re: Encapsulation, inheritance and polymorphism
 
On 07/17/12 12:24, Terry Reedy wrote:
> On 7/17/2012 8:01 AM, Lipska the Kat wrote:
>> 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


Only if Lipska had omitted the "-n" which tells sort to treat
numbers like numbers.

For Lipska, you'd want to look into the "csv" module for parsing the
file easily (specifying '\t' as the delimiter). You can then sort
and crop as-is, or you can use heapq.nsmallest()

-tkc





All times are GMT. The time now is 07:57 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.