Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 879561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:57:08+00:00 2026-05-15T11:57:08+00:00

Looking around for python implementations of tries just so that I can understand what

  • 0

Looking around for python implementations of tries just so that I can understand what they are and how they work, I came across Justin Peel’s patricia trie and found it very instructive: it’s straightforward enough for one as new as I am to play around with it and learn from it.

However there’s something I think I’m not understanding:

using Justin’s class patricia() thus:

>>> p = patricia()
>>> words = ['foo','bar','baz']
>>> for x in words:
...     p.addWord(x)

I get a trie as a dictionary looking like this:

>>> p._d
{'b': ['a', {'r': ['', {}], 'z': ['', {}]}], 'f': ['oo', {}]}

addWord() and isWord() work as expected, but isPrefix() shows the following behavior which puzzles me:

>>> p.isPrefix('b')
True
>>> p.isPrefix('f')
True
>>> p.isPrefix('e')
False

good, as expected; and then

>>> p.isPrefix('ba')
True

also good, but then:

>>> p.isPrefix('bal')
True

and furthermore:

>>> p.isPrefix('ballance')
True
>>> p.isPrefix('ballancing act')
True

Something here I’m not understanding?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:57:08+00:00Added an answer on May 15, 2026 at 11:57 am

    I believe the bug is in the following snippet of the code you’re looking at:

           if w.startswith(node[0][:wlen-i],i):
                if wlen - i > len(node[0]):
                    i += len(node[0])
                    d = node[1]
                return True
    

    it should actually be:

           if w.startswith(node[0][:wlen-i],i):
                if wlen - i > len(node[0]):
                    i += len(node[0])
                    d = node[1]
                else:
                    return True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tried looking around for a regex pattern for a full name and just can't
I've been looking around for a good MVC framework for Python using PyGTK. I've
I've been looking around the System.Xml namespace, but don't see anything that would support
I am looking for a Visual Studio add-in that would analyze the text around
I'm looking for a good, clean way to go around the fact that PHP5
I am looking for a financial library for Python that will enable me to
Someone has recently demonstrated to me that we can print variables in Python like
I'm looking around for a Java code signing certificate so my Java applets don't
I've been looking around for some decent tutorials on .NET remoting (old style MarshallByRef),
This is a fairly involved bug, and I've tried looking around to find other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.