Counting word strokes while parsing Trie tree

I'm trying to solve the keyboard autocompletion problem described here.
The problem is to calculate how many keystrokes a word requires, given some dictionary and autocomplete rules. For example, for the dictionary:

data = ['hello', 'hell', 'heaven', 'goodbye']

We get the following results (please refer to the link above for further explanations):

{'hell': 2, 'heaven': 2, 'hello': 3, 'goodbye': 1}

Quick explanation: if the user types

h

, then

e

is autocompleted because all words starting with

h

also have

e

as second letter. Now if the user types in

l

, the other

l

is filled, giving 2 strokes for the word

hell

. Of course,

hello

would require one more stroke. Please, see the link above for more examples.