autocomplete algorithm python