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

  • Home
  • SEARCH
  • 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 705473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:03:27+00:00 2026-05-14T04:03:27+00:00

Suppose you take the strings ‘a’ and ‘z’ and list all the strings that

  • 0

Suppose you take the strings ‘a’ and ‘z’ and list all the strings that come between them in alphabetical order: [‘a’,’b’,’c’ … ‘x’,’y’,’z’]. Take the midpoint of this list and you find ‘m’. So this is kind of like taking an average of those two strings.

You could extend it to strings with more than one character, for example the midpoint between ‘aa’ and ‘zz’ would be found in the middle of the list [‘aa’, ‘ab’, ‘ac’ … ‘zx’, ‘zy’, ‘zz’].

Might there be a Python method somewhere that does this? If not, even knowing the name of the algorithm would help.

I began making my own routine that simply goes through both strings and finds midpoint of the first differing letter, which seemed to work great in that ‘aa’ and ‘az’ midpoint was ‘am’, but then it fails on ‘cat’, ‘doggie’ midpoint which it thinks is ‘c’. I tried Googling for “binary search string midpoint” etc. but without knowing the name of what I am trying to do here I had little luck.

I added my own solution as an answer

  • 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-05-14T04:03:28+00:00Added an answer on May 14, 2026 at 4:03 am

    If you define an alphabet of characters, you can just convert to base 10, do an average, and convert back to base-N where N is the size of the alphabet.

    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    
    def enbase(x):
        n = len(alphabet)
        if x < n:
            return alphabet[x]
        return enbase(x/n) + alphabet[x%n]
    
    def debase(x):
        n = len(alphabet)
        result = 0
        for i, c in enumerate(reversed(x)):
            result += alphabet.index(c) * (n**i)
        return result
    
    def average(a, b):
        a = debase(a)
        b = debase(b)
        return enbase((a + b) / 2)
    
    print average('a', 'z') #m
    print average('aa', 'zz') #mz
    print average('cat', 'doggie') #budeel
    print average('google', 'microsoft') #gebmbqkil
    print average('microsoft', 'google') #gebmbqkil
    

    Edit: Based on comments and other answers, you might want to handle strings of different lengths by appending the first letter of the alphabet to the shorter word until they’re the same length. This will result in the “average” falling between the two inputs in a lexicographical sort. Code changes and new outputs below.

    def pad(x, n):
        p = alphabet[0] * (n - len(x)) 
        return '%s%s' % (x, p)
    
    def average(a, b):
        n = max(len(a), len(b))
        a = debase(pad(a, n))
        b = debase(pad(b, n))
        return enbase((a + b) / 2)
    
    print average('a', 'z') #m
    print average('aa', 'zz') #mz
    print average('aa', 'az') #m (equivalent to ma)
    print average('cat', 'doggie') #cumqec
    print average('google', 'microsoft') #jlilzyhcw
    print average('microsoft', 'google') #jlilzyhcw
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple query that is suppose to take user inputted text and
I have a list of strings (a List<String> ) that can have anywhere from
suppose i'm implementing a polymorphic tree data structure that can take on data of
I'm supposed to write this c++ that take in 01 and on. for example:
The code is suppose to take a string of multiple arguments and split them
Suppose that I have the following string: http://www.domain.com/?s=some&two=20 How can I take off what
I have a function I've written that was initially supposed to take a string
I suppose I could take a text and remove high frequency English words from
Suppose I have a function which can either take an iterable/iterator or a non-iterable
Suppose I have one long long int and want to take its bits and

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.