[Tutor] appending/updating values dict key value pairs
Sivaram Neelakantan
nsivaram.net at gmail.com
Sun Jun 23 11:42:31 CEST 2013
On Sun, Jun 23 2013,Alan Gauld wrote:
[snipped 21 lines]
> But we normally call methods via the object instance rather than the
> class so simplifying this further we get:
>
> b['a'].append('c')
>
Thanks for the detailed explanation.
I've sort of used a dict of this sort {'a': [1,2,'fff'] } in my
programs and I've noticed that I've got to unpack the list with
hardcoded list positions when I retrieve the value of a key.
I think I'd be better off, if I did something of
{'a' : ['foo': 1, 'bar':2, 'offset': 'fff'] }
wouldn't that be better from a maintainability POV? Are there any
examples of such? Or is there a 'struct' option for python? I don't
want to use OO methods for now.
sivaram
--
More information about the Tutor
mailing list