0

I am having trouble creating a function since I want to be able to refer to the tuple and not the list which contains the tuples. Hence I have come to the conclusion that I want to get rid of the inner square brackets.

I have a list similar to this: List=[[(1,2),(3,4),(5,6)],[(1,2),(5,7),(3,8)],[...],[...]]

So the question I am asking is how can I remove the inner [ ] so that I can just produce a single list of tuples.

Also, I am not sure if I am allowed to ask another question, but how would i also delete duplicates (x,y) entries in my new list?

I have not provided code for this since I know the problem for the code I have and I believe I would confuse people by including it. If however, you wish to see the code, or want me to clarify anything please let me know.

quiet_laika
  • 174
  • 10
ViB
  • 65
  • 8
  • For reference, this is typically known at "flattening" the list. For the second question, a google search will lead you to many existing solutions. – Carcigenicate Apr 07 '19 at 19:53
  • @Carcigenicate that is indeed what I am looking for, thank you for pointing this out. – ViB Apr 07 '19 at 19:57

1 Answers1

1

I think this has been asked and answered on here multiple times. The solution to the flattening problem would be as follows:

new_list = [tupl for l in List for tupl in l]
emilaz
  • 1,722
  • 1
  • 15
  • 31