Re: Why I have to do a deepcopy to the argument?

2010-06-16 Thread Dimitris Leventeas
""" if (position is not None) and (position >= 1): embedded_obj = [0] * position embedded_obj.append({}) else: embedded_obj = {} d2 = trie for i, character in enumerate(sequence): d2 = access_trie(trie, sequence[:

Why I have to do a deepcopy to the argument?

2010-06-15 Thread Dimitris Leventeas
0, {}]}]}]} >>> trie = {} >>> trie = populate_trie(trie, 'heh', 1) >>> populate_trie(trie, 'hah', 1) {'h': [2, {'a': [1, {'h': [1, {}]}], 'e': [1, {'h': [1, {}]}]}]} """ if (position is not None) and (position >= 1): embedded_obj = [0] * position embedded_obj.append({}) else: embedded_obj = {} d = deepcopy(trie) d2 = d for i, character in enumerate(sequence): d2 = access_trie(d, sequence[:i], position) if character not in d2: if position is None: d2[character] = deepcopy(embedded_obj) else: d2[character] = d2.get(character, deepcopy(embedded_obj)) d2[character][0] += 1 elif position is not None: d2[character][0] += 1 return d Best regargs, Dimitris Leventeas -- Dimitris Leventeas http://students.ceid.upatras.gr/~lebenteas/ -- http://mail.python.org/mailman/listinfo/python-list