Re: Encapsulation, inheritance and polymorphism

Discussion in 'Python' started by MRAB, Jul 17, 2012.

  1. MRAB

    MRAB Guest

    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.
     
    MRAB, Jul 17, 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:
    202
    Devin Jeanpierre
    Jul 17, 2012
  2. Ulrich Eckhardt
    Replies:
    72
    Views:
    1,042
    Mark Lawrence
    Aug 19, 2012
  3. Terry Reedy
    Replies:
    0
    Views:
    210
    Terry Reedy
    Jul 17, 2012
  4. Tim Chase
    Replies:
    0
    Views:
    180
    Tim Chase
    Jul 17, 2012
  5. Arnaud Delobelle
    Replies:
    0
    Views:
    174
    Arnaud Delobelle
    Jul 18, 2012
Loading...

Share This Page