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


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

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

Started byBen Finney <ben+python@benfinney.id.au>
First post2014-04-10 15:25 +1000
Last post2014-04-10 15:25 +1000
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: how to make ["a", "b", ["c", "d"], "e"] into ['a', 'b', 'c', 'd', 'e'] ? Ben Finney <ben+python@benfinney.id.au> - 2014-04-10 15:25 +1000

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

FromBen Finney <ben+python@benfinney.id.au>
Date2014-04-10 15:25 +1000
SubjectRe: how to make ["a", "b", ["c", "d"], "e"] into ['a', 'b', 'c', 'd', 'e'] ?
Message-ID<mailman.9116.1397107567.18130.python-list@python.org>
length power <elearn2014@gmail.com> writes:

> maybe there is a more smart way to do.

Maybe. But a way to do what, exactly?

You start with a list, but what is it exactly that you want to do with
that list?

    >>> x = ["a", "b", ["c", "d"], "e"]

If I interpret your request *literally*, I can achieve it in a single
statement::

    >>> y = ['a', 'b', 'c', 'd', 'e']

There! We got the second list you wanted.

Maybe you want to turn the second item in any list into ‘['c', 'd']’::

    >>> y = x[:2] + ['c', 'd'] + x[3:]

Or maybe you want some other operation. It's not clear from your example.

So, thank you for providing an example of what you mean; but that
doesn't help with knowing what you mean *generally*.

What is the general operation you want to do? Please describe what input
you will get, and what the output should be in the same terms.

-- 
 \        “Ubi dubium, ibi libertas.” (“Where there is doubt, there is |
  `\                                                        freedom.”) |
_o__)                                                                  |
Ben Finney

[toc] | [standalone]


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


csiph-web