Merge branch 'master' of https://github.com/mgrove36/python-projects
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
# import module to sort characters in order of frequency
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
# function to find path of desired character
|
# function to find path of desired character
|
||||||
@@ -35,7 +36,7 @@ for item in info:
|
|||||||
frequencies.append(item[1])
|
frequencies.append(item[1])
|
||||||
|
|
||||||
# repeat until only one top-level node exists
|
# repeat until only one top-level node exists
|
||||||
while len(nodes) > 1:
|
while len(nodes) > 2:
|
||||||
# combine two least frequent characters' nodes into a new tuple node, containing the old nodes (old_node_1, old_node_2)
|
# combine two least frequent characters' nodes into a new tuple node, containing the old nodes (old_node_1, old_node_2)
|
||||||
new_node = (nodes[0], nodes[1])
|
new_node = (nodes[0], nodes[1])
|
||||||
# combine two least frequent characters' frequencies into a total frequency, to be used at the top level of the list of nodes
|
# combine two least frequent characters' frequencies into a total frequency, to be used at the top level of the list of nodes
|
||||||
|
|||||||
Reference in New Issue
Block a user