I want to use sets as data structure. how should i make it possible? what are the commands I need?
Like closedset = set()
is this ok?
And in a set, if i want to get some value out, what is the command for that one?
I want to use sets as data structure. how should i make it possible? what are the commands I need?
Like closedset = set()
is this ok?
And in a set, if i want to get some value out, what is the command for that one?
Correct. To create an empty set, write foo = set(). To retrieve values, you can iterate over the set:
for val in someset:
print val
You can also write val in someset to check if an item is in a set.
Be sure to read the documentation for how to do set operations.
You can saymySet = set(), which will give you a blank set to work with. Additionally, one method I found useful usually is converting from tuples/lists to sets, which you can do by saying mySet = set([1,2,3,4,5]).
What do you mean you'd like to get some value out? As in whether or not an item is a member of the set? For determining membership, you can use the usual python idiom of 1 in mySet to determine whether 1 is in the set or not.
And yes, the docs are right here