Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25823

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <drobinow@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.031
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; '22,': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.10; 'list)': 0.16; 'map(int,': 0.16; 'reason.': 0.16; 'received:209.85.161.174': 0.16; 'sequence.': 0.16; 'subject:Converting': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'file.': 0.20; 'cc:2**0': 0.23; "i've": 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'message- id:@mail.gmail.com': 0.27; 'subject:list': 0.28; "i'm": 0.29; 'code': 0.31; 'could': 0.32; 'everyone': 0.33; 'hi,': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'list': 0.35; 'returning': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'functional': 0.36; 'does': 0.37; 'option': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'performance': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'more': 0.63; 'jul': 0.65; 'brain,': 0.84; 'clearer': 0.84; 'quicker': 0.84; 'am.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=oebr8Pbwyw665OBD9EikRtiKQpqSrf5lR8hjX7mFsNc=; b=LIEnGaD8TYTzDBbZo476rkNcHlSh+SaLLG2pFWXmOYxouy4OGWVyZBFWwNbVszvlPI 5yNw0EylSLqGz/Ka738Wv9Dc24l8wpDUKkynlBCRApCmHXDfBSuXrzgO6x20egRon31U w5dK/1nCTw7xJsWqhq4e17bLlTEmtV+dD7dGDq9smtwSMYcQXGOGXhCDXo7ylK7l/GUc mATIy3ll5OhiNn4MJXQL968PPeqQkFfNi65Q8sRTBCSbWDs53P6kP0jF0Qv/BweSo4nB BYqr+DRe1xFDUCL3xouL96XvF/Ek49WuYM+g+6+OVpwK/uOVgn8qbu1ZPXvcLxCsKVLC 7M1A==
MIME-Version 1.0
In-Reply-To <500C2842.4040204@freenet.de>
References <3rCdnUCiWpP1gZHNnZ2dnUVZ7vQAAAAA@giganews.com> <e9VOr.124006$PE.28478@fx04.am4> <500C2842.4040204@freenet.de>
Date Sun, 22 Jul 2012 13:03:10 -0400
Subject Re: Converting a list of strings into a list of integers?
From David Robinow <drobinow@gmail.com>
To janpeterr@freenet.de
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2433.1342976600.4697.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342976600 news.xs4all.nl 6946 [2001:888:2000:d::a6]:41683
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25823

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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