September 16, 2020 at 12:00 am
Comments posted to this topic are about the item Updating Python Dictionary Values
September 16, 2020 at 8:50 am
I think this is a bad solution, because you re-set the whole entry for key 1 again. Why not use the following?
people[1]['last_name'] = 'Dactill'
September 16, 2020 at 1:34 pm
Thanks for the feedback!
I think this is a bad solution, because you re-set the whole entry for key 1 again. Why not use the following?
people[1]['last_name'] = 'Dactill'
I agree, it does seem somewhat counter-intuitive to pass the dictionary again associated with the first key as well as repeating the values. Programatically, this would also be more difficult to achieve. I shared that solution as I found it to be a bit more simpler.
I agree it is bad practice.
If this was intended as update showcase:
people[1].update(last_name='Dactill')
I like this solution a lot, thank you for sharing! There are almost infinite possibilities of alternate ways to achieve our desired outcome. This one certainly would have been easier to understand with knowledge of indexing dictionaries. The update demonstration would have been much easier without a nested dictionary in this case.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply