tree[nucelotide_postionc][nucleotide]=default(value subtree) This should
be returned when doing lookup without any
tree[nucelotide_postionc][nucleotide]=Postive value
tree[nucelotide_postionc][nucleotide]=Negative value
I'm sorry, I don't understand what you are asking. What are tree,
nucelotide_postionc, nucleotide, subtree? What are positive value and
negative value?
If each key has multiple values, how do you want to specify which value
to return?
The simplest way to associate multiple values with a key is to use a list:
>>> d = {}
>>> d['a'] = [2, 3, 4]
>>> d['b'] = [5, 6]
>>> d['a'].append(0)
>>> d
{'a': [2, 3, 4, 0], 'b': [5, 6]}
If you like, you can take the convention that the first item in the list
is the default, and write this:
>>> print d['b'][0]
5
--
Steven
You could use the collections.defaultdict method.
>>> import collections
>>> example1 = collections.defaultdict(int)
>>> example1[1]
0
>>> example2 = collections.defaultdict(list)
>>> example2[1]
[]
>>> example3 = collections.defaultdict(dict)
>>> example3[1]
{}
>>> # Make nested default dictionary
>>> def getNewOuterDictionary():
... return collections.defaultdict(getNewInnerDictionary)
>>> def getNewInnerDictionary():
... return collections.defaultdict([])
>>> example4[1][1]
[]
Hope that helps.
--
Roy Hyunjin Han
http://invisibleroads.com
Training people to become software developers and connecting them to jobs
and projects for local businesses
You could use the collections.defaultdict method.
>>> >>> import collections
>>> >>> example1 = collections.defaultdict(int)
>>> >>> example1[1]
0
>>> >>> example2 = collections.defaultdict(list)
>>> >>> example2[1]
[]
>>> >>> example3 = collections.defaultdict(dict)
>>> >>> example3[1]
{}
>>> >>> # Make nested default dictionary
>>> >>> def getNewOuterDictionary():
... return collections.defaultdict(getNewInnerDictionary)
>>> >>> def getNewInnerDictionary():
... return collections.defaultdict([])
>>> >>> example4[1][1]
[]
Hope that helps.
--
Roy Hyunjin Han
http://invisibleroads.com
We train people to become software developers and connect them to jobs and
projects for local businesses.