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


Groups > comp.lang.python > #70010 > unrolled thread

how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?

Started bylength power <elearn2014@gmail.com>
First post2014-04-10 13:14 +0800
Last post2014-04-10 10:36 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? length power <elearn2014@gmail.com> - 2014-04-10 13:14 +0800
    Re: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? pete.bee.emm@gmail.com - 2014-04-10 10:36 -0700

#70010 — how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?

Fromlength power <elearn2014@gmail.com>
Date2014-04-10 13:14 +0800
Subjecthow to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?
Message-ID<mailman.9113.1397106891.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

>>> x=["a","b",["c","d"],"e"]
>>> y=x[2]
>>> y
['c', 'd']
>>> x.insert(2,y[0])
>>> x
['a', 'b', 'c', ['c', 'd'], 'e']
>>> x.insert(3,y[1])
>>> x
['a', 'b', 'c', 'd', ['c', 'd'], 'e']
>>> del x[4]
>>> x
['a', 'b', 'c', 'd', 'e']
>>>
maybe there is a more smart way to do.

[toc] | [next] | [standalone]


#70049

Frompete.bee.emm@gmail.com
Date2014-04-10 10:36 -0700
Message-ID<b15e1d34-8030-4cf5-8e12-309aa0ad4d4f@googlegroups.com>
In reply to#70010
I've been using compiler.ast.flatten, but I have comments indicating it will need be replaced if/when I move to Python 3. 

I don't pollute my code base with flatten, I just call my own version in my utility library that is currently redirecting to flatten.

flatten works equally well with tuples as lists and I'm going to remain consistent with that. My version returns a tuple as well. 

My love affair with the immutable, hashable, and wonderfully named tuple is perhaps something that needs its own thread, or private room. 


On Wednesday, April 9, 2014 10:14:49 PM UTC-7, length power wrote:
> >>> x=["a","b",["c","d"],"e"]
> >>> y=x[2]
> >>> y
> ['c', 'd']
> >>> x.insert(2,y[0])
> >>> x
> 
> ['a', 'b', 'c', ['c', 'd'], 'e']
> >>> x.insert(3,y[1])
> >>> x
> ['a', 'b', 'c', 'd', ['c', 'd'], 'e']
> 
> >>> del x[4]
> >>> x
> ['a', 'b', 'c', 'd', 'e']
> >>>
> maybe there is a more smart way to do.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web