I am having trouble with how to get the elements of the frozenset.

Asked 2 years ago, Updated 2 years ago, 20 views

I use networkX in python and frozenset as the vertex labeling.
I couldn't find a particular site even though I looked into how to get the elements of frozenset, so I wrote it down here.
I would appreciate it if you could refer to the examples below.

Example
·frozenset([1,2])
What you want to do: Get elements 1 and 2
Trouble: Unable to retrieve elements

python

2022-09-30 19:12

2 Answers

There is also an option other than for .Take it out and choose according to how you want to use it.

>>f=frozenset([1,2])
>>f
frozenset ({1,2})
>> list(f)
[1, 2]
>> set(f)
{1, 2}
>>tuple(f)
(1, 2)


2022-09-30 19:12

Set is out of order, so it cannot be retrieved like a list
Therefore, you must remove it with for.


s=frozenset ([1,2])
for value in:
    print(value)//1,2


2022-09-30 19:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.