I want to get the first value for "Forest" but im getting an "o"
zones = {"Forest":[1,50]}
for area in zones:
spawnChance = area[1]
print spawnChance
I want to get the first value for "Forest" but im getting an "o"
zones = {"Forest":[1,50]}
for area in zones:
spawnChance = area[1]
print spawnChance
Python dicts when used as iterables yield their keys. As a result, area
is equal to "Forest" in your example.
Also, index of first element in array is zero, not one (I believe only Basic uses one-based lists/arrays).
To access both keys and values use items
or, better, iteritems
(consult with this question on SO for difference between them)
for key, value in zones.iteritems():
spawnChance = value[0]
Also, if you don't really care about the key, you can just use values
:
for area in zones.values():
spawnChance = area[0]
If you want to keep the code, use dict[key]
to get te value.
zones = {"Forest":[1,50]}
for area in zones:
spawnChance = zones[area][1]
print spawnChance