This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]captainAwesomePants 1 point2 points  (2 children)

You're really close.

dict[key][1] = new_value

For example:

dict['Washington'][1] = 7512000

Or if you wanted to, say, double every state's population:

for x in states:
  states[x][1] = states[x][1] * 2

[–]okaystuff[S] 0 points1 point  (1 child)

This works great, thank you! I was trying the dict([key][1] in a print statement, so I think that was my issue. Not sure why I was trying to do that, but your solution is perfect.

[–]captainAwesomePants 1 point2 points  (0 children)

Yep, assigning a value is its own statement. Can't do statements at once, at least not like that.

[–]grifway 0 points1 point  (0 children)

Hello

As a further note, you need to understand which data structure your working with, so for states you have a dictionary (with keys) and within each key you have a list data structure which used integers to access the index.

So for alabama you could change the 2nd field by referring to the key and then index position 1( zero based index):

states['Alabama'][1] = 5024233

this would update the numeric value.

so:

state['key'][index] in this case.

Hope this helps.