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 9154255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:23:59+00:00 2026-06-17T12:23:59+00:00

I need to evaluate levenshtein edit distance on unicode strings, which means that two

  • 0

I need to evaluate levenshtein edit distance on unicode strings, which means that two strings containing identical content will need to be normalized to avoid biasing the edit distance.

Here is how I generate random unicode strings for my tests:

def random_unicode(length=10):
    ru = lambda: unichr(random.randint(0, 0x10ffff))
    return ''.join([ru() for _ in xrange(length)])

And here is the simple test case that is failing:

import unicodedata
uni = random_unicode()
unicodedata.normalize(uni, 'NFD')

And here is the error:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-9: ordinal not in range(128)

I checked to make sure that uni was, indeed, a unicode object:

u'\U00020d93\U000fb2e6\U0005709a\U000bc31e\U00080262\U00034f00\U00059941\U0002dd09\U00074f6d\U0009ef7a'

Can someone enlighten me?

  • 1 1 Answer
  • 0 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-06-17T12:24:00+00:00Added an answer on June 17, 2026 at 12:24 pm

    You’ve switched the parameters of normalize. From the relevant documentation:

    unicodedata.normalize(form, unistr)

    Return the normal form form for the Unicode string * unistr*. Valid values for form are ‘NFC’, ‘NFKC’, ‘NFD’, and ‘NFKD’.

    The first argument is the form, and the second is the string to be normalized. This works just fine:

    unicodedata.normalize('NFD', uni)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a test for a variable which would evaluate to true in two
we need to compare the content of 2 identical gridviews and extract rows that
Say i have a string that i need to evaluate in javascript such as
I have a homework and I need to evaluate which approach is better according
I need to evaluate the sum of the row: 1/1+1/2+1/3+...+1/n. Considering that in C++
I have logical expressions that I need to evaluate. After some expresison template parametrized
Possible Duplicate: Convert String to code I need to evaluate a string containing valid
I need to evaluate the effectiveness of algorithms which predict the probability of something
I need to evaluate whether two formulas are equivalent or not. Here, I use
I need to evaluate a mathmatical expression that is presented to me as a

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.