I'm looking for a bit of help on a piece of python code I've been writing for fun, the troublesome piece of code is thus:
v = randint(1,7) if v != 7: d = randint(1,5) if d == 1: print(vdset[v], file=text_file)
My aim is to use randint to select a random value from my set, however, when running I get the error that
'set' object does not support indexing. I suppose then that I need to replace my use of
set with something else, but I am unsure as to what would work.
The problem is that a set is an unordered collections of unique element. You should have a look at data structure for Python :
You can try :
v = randint(1,7) if v != 7: d = randint(1,5) if d == 1: print(list(vdset)[v], file=text_file)