#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0

    Efficent string search


    I have a list containing int's, i need to find the string containing the largest int i.e. the max integer in the list

    how to go about this

    list = ['1', '2', '3', '4' ...] etc

    i.e. I want to find the largest int in the list...this list is in the thousands
  2. #2
  3. No Profile Picture
    Brony & F/OSS Advocate
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2003
    Location
    Anaheim, CA (USA)
    Posts
    6,653
    Rep Power
    2476
    Originally Posted by Elbi
    I have a list containing int's, i need to find the string containing the largest int i.e. the max integer in the list

    how to go about this

    list = ['1', '2', '3', '4' ...] etc
    What have you tried so far? What are you having trouble with? Where is the confusion?

    From how it's worded, this seems very much like a homework question. If so, we'll still point you in the right direction; but please remember that these are for you to learn from the experience, so our providing an immediate solution will not help you.
    ~~ Peter ~~ :: ( Who am I? ) :: ( Peter's Musings: Uploading myself, bit by bit... ) :: ( Electronic Frontier Foundation ) :: ( I'm a GNU/Linux addict and Free Software Advocate. ) :: ( How to Ask Questions the Smart Way ) :: ( The Fedora Project, sponsored by Red Hat ) :: ( GNOME: The Free Software Desktop Project ) :: ( GnuPG Public Key ) :: ( About me on the WIki )
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,890
    Rep Power
    481
    I'll help a little bit.
    ['1', '2', '3', '4' ]

    is not a list of integers.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0
    Originally Posted by codergeek42
    What have you tried so far? What are you having trouble with? Where is the confusion?

    From how it's worded, this seems very much like a homework question. If so, we'll still point you in the right direction; but please remember that these are for you to learn from the experience, so our providing an immediate solution will not help you.
    This is not a homework. I have to solve a prod issue and I'm looking for the best solution

    I can iterate thru the list, cast each to an int and compare to previous value,

    i.e
    maxval = None
    for s in strlist:
    if int(s) > maxVal:
    maxVal = int(s)

    return maxVal

    or something of the sort. I'm looking for an efficient way to do this, wondering if Python has any libs that has improved algorithm
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,890
    Rep Power
    481
    max(int(s) for s in LIST)
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0
    Originally Posted by b49P23TIvg
    max(int(s) for s in LIST)
    Gratitude

IMN logo majestic logo threadwatch logo seochat tools logo