Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Converting a list of strings into a list of integers?

Reply
Thread Tools

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

 
 
Jan Riechers
Guest
Posts: n/a
 
      07-22-2012
On 22.07.2012 20:03, David Robinow wrote:
> On Sun, Jul 22, 2012 at 12:20 PM, Jan Riechers <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Converting a list of strings into a list of integers? Jan Riechers Python 4 07-23-2012 03:31 PM
Re: Converting a list of strings into a list of integers? Ian Kelly Python 0 07-22-2012 05:16 PM
Re: Converting a list of strings into a list of integers? David Robinow Python 0 07-22-2012 05:03 PM
Re: Converting a list of strings into a list of integers? Paul Rubin Python 0 07-22-2012 05:03 PM
Re: Converting a list of strings into a list of integers? Roy Smith Python 1 07-22-2012 04:30 PM



Advertisments