Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70013
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: how to make ["a", "b", ["c", "d"], "e"] into ['a', 'b', 'c', 'd', 'e'] ? |
| Date | 2014-04-10 15:25 +1000 |
| References | <CAOmh462zZbe29dPL1nV7YokJObwuHXu0_K5PxD1gUr_=RB73mA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9116.1397107567.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
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
csiph-web