A list of data structures in Python -
A list of data structures in Python -
i pretty new python (coming java background) wondering if have advice on info construction design question. need create info construction default values this:
[ (name=”name1”, {id=1, val1=”val1”} ), (name=”name2”, {id=2, val1=”val2”} ) ]
i.e list of tuples each tuple consists of 1 string value (name) , dictionary of values.
the first piece of functionality need able add together or override above info construction additional details e.g:
[ (name=”name2”, {id=2, val1=”new value”} ) , (name=”name2”, {id=3, val1=”another value”} ) , (name=”name3”, {id=3, val1=”val3”} ) ]
which result in final info construction looks this:
[ (name=”name1”, {id=1, val1=”val1”} ), (name=”name2”, {id=2, val1=”new value”} ) , (name=”name2”, {id=3, val1=”another value”} ) , (name=”name3”, {id=3, val1=”val3”} ) ]
the sec piece of functionality need able access each tuple in list according id value in dictionary i.e
get me tuple name = “name2” , id=”3” .
could give me opinions on how best implemented in python?
thanks!
the namedtuple closest wrote others have said, there may improve designs want.
python data-structures
Comments
Post a Comment