Dictionary Purchase Exercise help

12 views
Skip to first unread message

The Grugnas

unread,
Mar 28, 2018, 5:47:55 PM3/28/18
to Building Skills Books
Hi, first of all I wanted to thank the author of the book which seems to be very active and wrote a really amazing book!
As I am a newbie at python (i only have academic programming knowledge), I am getting trouble into understanding that dictionary exercise.
If i create a dict of a list element (which is a tuple, thus statically allocated and not resizeable) i can't update the previously created dictionary element by appending another block to the already existing dictionary value ( which is a list ).
Or, at least, this is what the exercise asks for, as far as i understand (i am sorry as english isn't my first language).
Can I have some help with that exercise on page 183 section 16.9 with an eventual code solution please?

Steven Lott

unread,
Mar 28, 2018, 10:06:37 PM3/28/18
to building-s...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Building Skills Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to building-skills-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
A tuple and a list are dramatically different. They are both sequence collections. A list is mutable and can be changed. 

a = {‘key’: [1, 2]}
a[‘key’].append(3)

Does modify the list. Try it. 
--
"It May Be A Hack, But It Works"
Reply all
Reply to author
Forward
0 new messages