Converting a list of strings into a list of integers?
Grant Edwards
invalid at invalid.invalid
Mon Jul 23 10:27:19 EDT 2012
On 2012-07-22, Jan Riechers <janpeterr at freenet.de> wrote:
> 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.
"map" is what comes to mind first for me, but that's probably because
1) Before I learned Python, I learned other more functional languages
where map was the definitive answer.
2) When I first learned Python it didn't have list comprehensions.
That said, "map" seems to be frowned upon by the Python community for
reasons I've never really understood, and most people are going to
prefer reading a list comprehension. "What most people are going to
prefer reading" does matter...
--
Grant Edwards grant.b.edwards Yow! ... the MYSTERIANS are
at in here with my CORDUROY
gmail.com SOAP DISH!!
More information about the Python-list
mailing list