How to convert frozenset to normal sets or list?
We can convert frozenset object x
to list or set by using list() or set() on it. So we can do this on each item in the list containing frozensets as mentioned in the another by Ivan
>>> x=frozenset(['a','b','c','d'])
>>> print(x)
frozenset({'c', 'd', 'a', 'b'})
>>> y=list(x)
>>> y
['c', 'd', 'a', 'b']
>>> y = set(x)
>>> y
{'c', 'd', 'a', 'b'}
sets=[frozenset({'a', 'c,'}), frozenset({'h,', 'a,'})]
print([list(x) for x in sets])
The list comprehension will convert every frozenset in your list of sets and put them into a new list. That's probably what you want.
You can also you map, map(list, sets)
. Please be aware, that in Python 3, if you want the result of map
as list you need to manually convert it using list
, otherwise, it's just a map object
which looks like <map object 0xblahblah>