I'm studying about sets ( set
) in Python because I'm going to use an algorithm to find paths in a graph, it's for a college discipline I'm having.
I created two assembly examples using two different notations. Look at the illustration example:
foo = {1, 1, 5, 'gato', 'Oie'}
baz = set([2, 19, 51, 'stack', 'py'])
print(foo)
print(baz)
However, when I try to access some value of the two sets foo
or baz
using index baz[0]
it returns an error saying that the object does not support indexing, see:
Traceback (most recent call last): File "jdoodle.py", line 11, in <module> print(baz[2]) TypeError: 'set' object does not support indexing Command exited with non-zero status 1
Question
So, I'd like to know how I could access the elements of a set individually?