-3

Given that

g=[[1,2,3,4],[4,5,6],[6,7],[10,11]]

What code should I use to get [[1,2,3,4,5,6,7],[10,11]]?

  • You should try some code then ask for working code. – Tanveer Alam Jan 07 '15 at 17:58
  • @iCodez: I disagree that's the right duplicate. If I read the question correctly, the OP is after a consolidation operation, not merely a flattening. – DSM Jan 07 '15 at 17:59
  • 2
    @DSM - That was not in the original question. The OP edited since then; he was just doing flattening before. I'll vote to reopen since this question is no longer a dupe (of the one I picked). –  Jan 07 '15 at 18:01
  • @NPE: I mean something like [this](http://rosettacode.org/wiki/Set_consolidation), a connected-components problem. Something like [this question](http://stackoverflow.com/questions/9110837/python-simple-list-merging-based-on-intersections). – DSM Jan 07 '15 at 18:02
  • @iCodez: "how to merge two sublists sharing any number in common?" was never about flattening, although it could definitely have been clearer. – DSM Jan 07 '15 at 18:03
  • Now (post-edit) it looks like a dupe of a much clearer question from the same OP. Go figure. O.o – NPE Jan 07 '15 at 18:09
  • Sorry for being confusing but I have just edited the code hope it makes more sense. – James Harroid Jan 07 '15 at 18:19
  • @NPE: Sorry for being confusing but I have just edited the code hope it makes more sense. – James Harroid Jan 07 '15 at 18:41
  • @iCodez: Sorry for being confusing but I have just edited the code hope it makes more sense. – James Harroid Jan 07 '15 at 18:41
  • 1
    @NaLai: Well, you keep editing the question, but it remains unclear how it's not a duplicate of your question from yesterday. – NPE Jan 07 '15 at 18:42

1 Answers1

0

This should work:

list(set(sum(g, [])))

Output:[1,2,3,4,5,6,7]

Community
  • 1
  • 1
Dominic Farolino
  • 1,362
  • 1
  • 20
  • 40