I have this code:
level = {0, 0, 0,
0, 1, 0,
0, 0, 0}
class player:
def getPlayerLoc(self, level):
for i in level:
if level[level.index(i)] == 1:
print "Player location = " + str(i)
p1 = player()
p1.getPlayerLoc(level)
When I run it it says:
Traceback (most recent call last):
File "gamy.py", line 13, in <module>
p1.getPlayerLoc(level)
File "gamy.py", line 8, in getPlayerLoc
if level[level.index(i)] == 1:
AttributeError: 'set' object has no attribute 'index'
It looks like it’s converting my array into a set object. Why is it doing this, and how can I fix it?
{}brackets meansset,declare it as a
list:e.g.