Re: Converting a list of strings into a list of integers?

Discussion in 'Python' started by Jan Riechers, Jul 22, 2012.

  1. Jan Riechers

    Jan Riechers Guest

    On 22.07.2012 20:03, David Robinow wrote:
    > On Sun, Jul 22, 2012 at 12:20 PM, Jan Riechers <> wrote:
    >> On 22.07.2012 18:39, Alister wrote:
    >>> looks like a classic list comprehension to me and can be achieved in a
    >>> single line
    >>> MODUS_LIST=[int(x) for x in options.modus_list]

    >> Hi,
    >>
    >> I am not sure why everyone is using the for-iterator option over a "map",
    >> but I would do it like that:
    >> MODUS_LIST= map(int, options.modus_list)
    >>
    >> "map" works on a list and does commandX (here "int" conversion, use "str"
    >> for string.. et cetera) on sequenceY, returning a sequence. More in the help
    >> file.
    >>
    >> And if I'm not completely mistaken, it's also the quicker way to do
    >> performance wise. But I can't completely recall the exact reason.

    > Because if you don't have a functional background 'map' is
    > unfamiliar. Although I've been aware of it for years I still can't
    > remember if it's map(int, list) or map(list,int) and although with a
    > small effort I could force it into my brain, I know that many of the
    > people reading my code are as ignorant as I am. The list comprehension
    > seems clearer to me.
    >
    >


    Hello,

    no offense by that, I just was wondering why everyone uses the list
    comprehension instead the built-in map in this case - I'm still using
    Python 2.7.3 so perhaps things might have changed a little. :)

    So far
    Jan
    Jan Riechers, Jul 22, 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. Roy Smith
    Replies:
    1
    Views:
    157
    Peter Otten
    Jul 22, 2012
  2. Jan Riechers
    Replies:
    4
    Views:
    210
  3. Paul Rubin
    Replies:
    0
    Views:
    155
    Paul Rubin
    Jul 22, 2012
  4. David Robinow
    Replies:
    0
    Views:
    160
    David Robinow
    Jul 22, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    131
    Ian Kelly
    Jul 22, 2012
Loading...

Share This Page