Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25824
| Date | 2012-07-22 20:10 +0300 |
|---|---|
| From | Jan Riechers <janpeterr@freenet.de> |
| Subject | Re: Converting a list of strings into a list of integers? |
| References | <3rCdnUCiWpP1gZHNnZ2dnUVZ7vQAAAAA@giganews.com> <e9VOr.124006$PE.28478@fx04.am4> <500C2842.4040204@freenet.de> <CAF3XjbybkbOtzQxidUaR_S_XDTxwewdxU8UZp7eiKCYdsKuhCQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2434.1342977192.4697.python-list@python.org> (permalink) |
On 22.07.2012 20:03, David Robinow wrote: > On Sun, Jul 22, 2012 at 12:20 PM, Jan Riechers <janpeterr@freenet.de> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Converting a list of strings into a list of integers? Tony the Tiger <tony@tiger.invalid> - 2012-07-22 10:29 -0500
Re: Converting a list of strings into a list of integers? Roy Smith <roy@panix.com> - 2012-07-22 11:39 -0400
Re: Converting a list of strings into a list of integers? Tony the Tiger <tony@tiger.invalid> - 2012-07-22 11:01 -0500
Re: Converting a list of strings into a list of integers? Peter Otten <__peter__@web.de> - 2012-07-22 18:30 +0200
Re: Converting a list of strings into a list of integers? Alister <alister.ware@ntlworld.com> - 2012-07-22 15:39 +0000
Re: Converting a list of strings into a list of integers? Tony the Tiger <tony@tiger.invalid> - 2012-07-22 11:01 -0500
Re: Converting a list of strings into a list of integers? Jan Riechers <janpeterr@freenet.de> - 2012-07-22 19:20 +0300
Re: Converting a list of strings into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-22 17:01 +0000
Re: Converting a list of strings into a list of integers? Jan Riechers <janpeterr@freenet.de> - 2012-07-22 20:27 +0300
Re: Converting a list of strings into a list of integers? Grant Edwards <invalid@invalid.invalid> - 2012-07-23 14:27 +0000
Re: Converting a list of strings into a list of integers? rusi <rustompmody@gmail.com> - 2012-07-23 08:31 -0700
Re: Converting a list of strings into a list of integers? David Robinow <drobinow@gmail.com> - 2012-07-22 13:03 -0400
Re: Converting a list of strings into a list of integers? Jan Riechers <janpeterr@freenet.de> - 2012-07-22 20:10 +0300
Re: Converting a list of strings into a list of integers? Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-22 11:16 -0600
Re: Converting a list of strings into a list of integers? Paul Rubin <no.email@nospam.invalid> - 2012-07-22 10:03 -0700
Re: Converting a list of strings into a list of integers? Dave Angel <d@davea.name> - 2012-07-22 21:03 -0400
csiph-web