f



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

--001a11c34e8edbc7c404f6a94bbe
Content-Type: text/plain; charset=ISO-8859-1

>>> 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.

--001a11c34e8edbc7c404f6a94bbe
Content-Type: text/html; charset=ISO-8859-1

<div dir="ltr"><div>&gt;&gt;&gt; x=[&quot;a&quot;,&quot;b&quot;,[&quot;c&quot;,&quot;d&quot;],&quot;e&quot;]<br>&gt;&gt;&gt; y=x[2]<br>&gt;&gt;&gt; y<br>[&#39;c&#39;, &#39;d&#39;]<br>&gt;&gt;&gt; x.insert(2,y[0])<br>&gt;&gt;&gt; x<br>
[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, [&#39;c&#39;, &#39;d&#39;], &#39;e&#39;]<br>&gt;&gt;&gt; x.insert(3,y[1])<br>&gt;&gt;&gt; x<br>[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, [&#39;c&#39;, &#39;d&#39;], &#39;e&#39;]<br>
&gt;&gt;&gt; del x[4]<br>&gt;&gt;&gt; x<br>[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<br>&gt;&gt;&gt;<br></div>maybe there is a more smart way to do.<br></div>

--001a11c34e8edbc7c404f6a94bbe--
0
length
4/10/2014 5:14:49 AM
comp.lang.python 77058 articles. 6 followers. Post Follow

1 Replies
1533 Views

Similar Articles

[PageSpeed] 50

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.
0
pete
4/10/2014 5:36:46 PM
Reply:

Similar Artilces:

Why """, not '''?
Why is """ the preferred delimiter for multi-line strings? On Mar 5, 9:56 am, MartinRineh...@gmail.com wrote: > Why is """ the preferred delimiter for multi-line strings? Is it ? FWIW, I use single quotes whenever I can and double whenever I have to (i.e. rarely). George On Wed, 5 Mar 2008 06:56:24 -0800 (PST) MartinRinehart@gmail.com wrote: > Why is """ the preferred delimiter for multi-line strings? Where did you see that? The only place I saw it was the style guide and it was only talking about docstrings. Even there they used "...

"Select" & "Order By" OK- ''WHERE'' Does'nt Work !
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've reduced my form request to a simple text string entry, instead of my desired optional parameters. As i have been stuck with a single unfathomable glitch for over a year. Basically, if i enter queries such as ; "select * from table" "select * from table order by artist", it works perfectly. However if i introduce the 'where' option, as in "select * from table where ...

html dir="rtl" does 'a b c' in same direction as "ltr" but '1 2 3' in different direction
http://www.frostjedi.com/terra/scripts/demo/rtl.html If you view the source, you'll see two divs - <div>a b c</div> and <div>1 2 3</div>. Both are displayed on the right hand side of the screen. <div>a b c</div> renders as 'a b c' but '1 2 3', instead, renders as '3 2 1' and I don't know why. Any ideas? On 2009-02-23, yawnmoth <terra1024@yahoo.com> wrote: > http://www.frostjedi.com/terra/scripts/demo/rtl.html > > If you view the source, you'll see two divs - <div>a b c</div> and &g...

'quote' to `quote'
Hi, what is the way to change 'shocking,' said Sally into `shocking', said Sally automatically as Tex read the author.txt file? Does this method also change "whatever happens," he said into ``whatever happens.'' he said. David R David R <angel_ov_north@tiscali.co.uk> wrote: > what is the way to change 'shocking,' said Sally > into `shocking', said Sally > automatically as Tex read the > author.txt file? It is possible (e.g. via an active '). But I suspect, this is a lot easier using a script language or similar. Also you ...

Mandis Quotes (aka retiring """ and ''')
Jef Raskin (namedropping) has pointed me at a neat scheme for quoting arbitrary textual matter called "Mandis quotes". Since google is ignorant of the phrase, I presume that Jef made it up. It is disgustingly simple, and very Pythonesque. Here's how it works: If you have a string that doesn't have any single quotes in it, you surround the string by a pair of doubled single quotes. ''Like this''. No backslash interpolation. If you want a character in there, you put it in there (yes, I know, stand down your armies). Clearly, then, any character except a si...

(mapcar 'quote '("1" "2" "3" "4"))
(mapcar 'quote '("1" "2" "3" "4")) returns ((quote "4") (quote "4") (quote "4") (quote "4")) Interesting and (for me) unexpected. Because (mapcar 'read '("1" "2" "3" "4")) returns (1 2 3 4) and (mapcar 'princ '("1" "2" "3" "4")) gives 1234("1" "2" "3" "4") Why isn't (mapcar 'quote '("1" "2" "3" "4&q...

Corectly convert from %PATH%=c:\\X;"c:\\a;b" TO ['c:\\X', 'c:\\a;b']
Hi, I am trying to treat an environment variable as a python list - and I'm sure there must be a standard and simple way to do so. I know that the interpreter itself must use it (to process $PATH / %PATH%, etc) but I am not able to find a simple function to do so. os.environ['PATH'].split(os.sep) is wrong on Windows for the case when PATH="c:\\A;B";c:\\D; where there is a ';' embedded in the quoted path. Does anyone know of a simple way (addons ok) which would do it in a cross platform way? If not - I will roll my own. My search has shown that generally people ...

Re: Mandis Quotes (aka retiring """ and ''')
Russell Nelson wrote: > If you need to put a single quote in, then you put > an arbitrary string in-between the single quotes which does NOT > appear in the string. For example, "Bill's house" becomes > 'x'Bill's house'x'. So possible examples might be: 'xx'somebody's mother'xx' 'xy'somebody's father'xy' 'wink'somebody's uncle'wink' 'quote'somebody's body'quote' not terrible easy on the eyes, and why use the single quote at all? Why no= t use a similar pattern li...

=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'
Hello. Well, I found this piece of code on php.net. Thats fine but where can i find explanation for all these ("|\')?([^ "\']*)("|\')?.*>([^<]*)' syntax so that I can construct my own rules for all kind of eregi preg and oter match functions ? Transform HTML links into plain-text "links" with the URL visible function AHREF2text($string) { return eregi_replace('<A .*HREF=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>', '[\\4] (link: \\2)', $string); } And another simple question, maybe ...

expect script : "expect 'X', send 'Y'" until expect "Z".
Hi. I am having some difficulties with an expect script, and was hoping someone could help me out here. I am running a scripted telnet session to some 'black box' appliance, and would like to retrieve the output of a particular command. However, the output of the command is longer than a single screen full. Since it was designed for interactive use, you get the magic string "[=More (xx%)=]" after each screenfull of output, at which point the command expects you to hit the spacebar in order to get another screenfull of output. Of course, I could just "send <space&...

Re: Mandis Quotes (aka retiring """ and ''') #2
Russell Nelson notes: > = > Choose poor examples, and then criticize them as poor choices? > = true enough, but the suggested scheme introduces another variable into the = language syntax; I might always make good choices <wink> on what delimiter = I choose, but I might also end up working on code written by someone else w= ho makes less good choices. Or vice versa. = > Exactly. It really would be better to have one(1) string literal > which can quote anything without reverting to backslashing. Why one? > Simpler parsing, simpler learning of the language, fewe...

JAXM returning '&lt;' and '&gt;' rather than "<" and ">"
Hi guys I'm up against a very annoying problem. I'm tryint to use JAXM to call a simple PHP nuSoap web service. I am using SOAPMessage/SOAPPart/SOAPEnvelope etc, however when i receive the message from the server i get: &lt;symbol&gt;great&lt;/symbol&gt; rather than: <symbol>great</symbol> Does anyone have any idea why its converting '<' to '&lt;'??? Any help would be most appreciated, i've been frustrated by this for hours! (Note the xml just dumps out "<symbol>great</symbol>" - it does not encode it ...

[9fans] acme and openning of ", "", '''chk' scripts (by rsc)
------=_Part_63992_24920993.1223483737771 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, is that an intention that acme does not recognize " (or "", not so sure about '''chk' ) to be a name of a valid file? At least " and "" seems to me to be a valid file name, but clicking on it with button 3 in acme doesn't work --- file is not opened. Only explicit use of Get opens it. Thanks Ruda ------=_Part_63992_24920993.1223483737771 Content-Type: text/html; charset=ISO-8859-1 Content...

what gives with "'import *' not allowed with 'from .'"?
I know the use of "from foo import *" is discouraged, but I'm writing a package that I hope others may want to integrate as a subpackage of their own projects, I know what I'm doing, and I want to use the "from .bar import *" syntax internally. It works fine with python-2.6, but with python-2.5 I get a SyntaxError: "'import *' not allowed with 'from .'" Judging from http://bugs.python.org/issue2400 , this issue was fixed back in May 2008, but it is still present with python-2.5.4, which was released in December. Why wont python-2.5 allow th...

Web resources about - how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ? - comp.lang.python

Resources last updated: 1/27/2016 1:46:01 AM