Re: Encapsulation, inheritance and polymorphism

Discussion in 'Python' started by Arnaud Delobelle, Jul 18, 2012.

  1. On 17 July 2012 13:01, Lipska the Kat <> 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
    Arnaud Delobelle, Jul 18, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Devin Jeanpierre
    Replies:
    0
    Views:
    177
    Devin Jeanpierre
    Jul 17, 2012
  2. Ulrich Eckhardt
    Replies:
    72
    Views:
    912
    Mark Lawrence
    Aug 19, 2012
  3. Terry Reedy
    Replies:
    0
    Views:
    186
    Terry Reedy
    Jul 17, 2012
  4. MRAB
    Replies:
    0
    Views:
    187
  5. Tim Chase
    Replies:
    0
    Views:
    154
    Tim Chase
    Jul 17, 2012
Loading...

Share This Page