Search code examples
pythonlistsetcurly-braces

remove curly brackets from a list of sets in python


my code looks something like this:

documents=set()
finals = []
temporary_set= set()
temporary_set.add(i)
finals.append(documents.intersection(temporary_set))

when i want to get all values from the finals list i use:

for final in finals:
    print (final)

This returns however the items as a set item within a list. like this:

[{27309053}, {23625724}, {25051134}]

How can i make it that the curly brackets will be omitted and that my result will look like this:

[27309053, 23625724, 25051134]

???


Solution

  • You can change

    finals.append(documents.intersection(temporary_set))
    

    to

    finals.extend(documents.intersection(temporary_set))
    

    which will add each element of that intersection to the list, rather than the intersection itself.