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


Groups > comp.lang.python > #5312

Re: How best to convert a string "list" to a python list

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <malaclypse2@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:" ': 0.03; 'method,': 0.07; 'python': 0.07; 'received:mail- bw0-f46.google.com': 0.09; 'subject:string': 0.09; 'pm,': 0.11; 'this:': 0.11; '>>>': 0.12; 'wrote:': 0.14; 'subject:python': 0.15; 'received:209.85.214.46': 0.16; 'splits': 0.16; '\xc2\xa0i': 0.16; 'subject:list': 0.22; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'message-id:@mail.gmail.com': 0.28; 'string': 0.29; 'fri,': 0.29; 'list': 0.30; 'it.': 0.31; 'to:addr:python-list': 0.32; 'things': 0.33; 'print': 0.35; 'list.': 0.35; 'doing': 0.36; 'some': 0.37; 'it?': 0.37; 'received:209.85': 0.37; 'strings': 0.38; 'received:google.com': 0.38; 'skip:" 20': 0.38; 'received:209.85.214': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'how': 0.39; 'header:Received:5': 0.40; '13,': 0.60; 'split': 0.60; '2011': 0.62; 'experts': 0.64; 'below.': 0.64; 'subject:best': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=TeDs0EnpyF2voGkYdQtDcu9Fb9LkaMi6HUvQQ9OuEwQ=; b=hPoMOR7jKHA4kae3auYAE8ZV+SeV8jl97qk0k0Y+C/r9htEbVupoeXg4EQtHnyac59 6YpANC3bJuGGiownBo0eTMQUR9Jq60tzRK5g7uoaXk/ka3K3v0LwCubcwnx38SapuSMp i9X+UL/DcZXxyRvkAdgrAdttq25L5dkki+o4Y=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=B5wBLSZ1ymwmXKtlHnSou9p7OtRR2ntoqxk1uX1mJCdCOEaC/gEUmkJ2LCQHCwJ6fR 2pqWFWxvLA8kcHaDaG6IlsN7bR34b92MyZFbSto454Q3Tq8jNZMukoOEkmYgYClcKtSW /RQ8y3g0iYrnv5IWjlYZH5jxBs8LpvUHXUszA=
MIME-Version 1.0
In-Reply-To <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com>
References <2efc3a05-22e5-46db-bd22-c95221bbd7b2@k16g2000yqm.googlegroups.com>
Date Fri, 13 May 2011 13:30:39 -0400
Subject Re: How best to convert a string "list" to a python list
From Jerry Hill <malaclypse2@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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.1519.1305307841.9059.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 82.94.164.166
X-Trace 1305307841 news.xs4all.nl 81483 [::ffff:82.94.164.166]:59026
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5312

Show key headers only | View raw


On Fri, May 13, 2011 at 1:15 PM, noydb <jenn.duerr@gmail.com> wrote:
> I want some code to take the items in a semi-colon-delimted string
> "list" and places each in a python list.  I came up with below.  In
> the name of learning how to do things properly, do you experts have a
> better way of doing it?

Strings have a split method, which splits the string into a list based
on a delimiter, like this:

>>> x = "red;blue;green;yellow"
>>> color_list = x.split(";")
>>> print color_list
['red', 'blue', 'green', 'yellow']

That's how I'd do it.

-- 
Jerry

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


Thread

How best to convert a string "list" to a python list noydb <jenn.duerr@gmail.com> - 2011-05-13 10:15 -0700
  Re: How best to convert a string "list" to a python list Jerry Hill <malaclypse2@gmail.com> - 2011-05-13 13:30 -0400
  Re: How best to convert a string "list" to a python list MRAB <python@mrabarnett.plus.com> - 2011-05-13 18:36 +0100
  Re: How best to convert a string "list" to a python list Redcat <redcat@catfolks.net> - 2011-05-13 19:26 +0000
  Re: How best to convert a string "list" to a python list Nobody <nobody@nowhere.com> - 2011-05-14 09:41 +0100
    Re: How best to convert a string "list" to a python list Daniel Kluev <dan.kluev@gmail.com> - 2011-05-14 21:16 +1100
    Re: How best to convert a string "list" to a python list Terry Reedy <tjreedy@udel.edu> - 2011-05-14 15:59 -0400

csiph-web