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

Discussion in 'Python' started by David Robinow, Jul 22, 2012.

  1. 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.
     
    David Robinow, 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:
    171
    Peter Otten
    Jul 22, 2012
  2. Jan Riechers
    Replies:
    4
    Views:
    222
  3. Paul Rubin
    Replies:
    0
    Views:
    164
    Paul Rubin
    Jul 22, 2012
  4. Jan Riechers
    Replies:
    0
    Views:
    158
    Jan Riechers
    Jul 22, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    143
    Ian Kelly
    Jul 22, 2012
Loading...

Share This Page