0

I want convert list as follow:

list=[['a','b','c','d'],'e','f']

to

list['a','b','c','d','e','f']

how could I do this....Helples..

  • What output do you expect for `[{1,2}, (3,4), '56', {7:8}, 9]`? – phihag Feb 06 '13 at 15:56
  • If you knew it was always going to take that particular shape, you could say: `list = list[0] + list[1:]` By the way, I know you're using `list` as an example name, but keep in mind that it's a built in function used to construct lists, so you shouldn't ever actually use that as a name. – Ben Mordecai Feb 06 '13 at 16:03
  • It is not particular shape,I still cannot figure out how to convert it.... – user1766864 Feb 06 '13 at 16:13

1 Answers1

0

Check out itertools.chain, I think it's exactly what you need: http://docs.python.org/2/library/itertools.html#itertools.chain


>>> import itertools as it
>>> li = [['e', 'f', 'g'], 'a', 'b']
>>> list(it.chain.from_iterable(li))
['e', 'f', 'g', 'a', 'b']

This is pretty much the example from the documentation of that function, which is always a good place to start...

BenDundee
  • 4,389
  • 3
  • 28
  • 34