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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:22:54+00:00 2026-06-03T19:22:54+00:00

I have a phone number range, for example: 3331234-3332345 I need to write a

  • 0

I have a phone number range, for example:

3331234-3332345

I need to write a function that converts it to list of prefixes:

3331234
...
3331239
333124
...
333129
33313
...
33319
33320
...
33322
333231
333232
333233
3332341
...
3332345

Question is not so easy. I don’t need to get a list of numbers between range start and end.

  • 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-03T19:22:56+00:00Added an answer on June 3, 2026 at 7:22 pm

    My working code. It not very quick, but working. Optimizations welcome.

    def fill(root, prefix, value, parent, pkey):
        if len(prefix) > 1:
            if prefix[0] in root:
                fill(root[prefix[0]], prefix[1:], value, root, prefix[0])
                if pkey:
                    if len(parent[pkey]) == 10:
                        parent[pkey] = value
            elif type(root) == type({}):
                root[prefix[0]] = {}
                fill(root[prefix[0]], prefix[1:], value, root, prefix[0])
                if pkey:
                    if len(parent[pkey]) == 10:
                        parent[pkey] = value
        elif type(root) == type({}):
            root[prefix[0]] = value
            if pkey:
                if len(parent[pkey]) == 10:
                    parent[pkey] = value
        return root
    
    def compact(prefixes, current):
        if not type(prefixes) == type({}):
            return [current]
        else:
            rlist = []
            for k, v in prefixes.iteritems():
                rlist.extend(compact(v, current + k))
                continue
            return rlist
    
    if __name__ == '__main__':
        plist = {}
        for x in range(4440000, 4490000):
            fill(plist, str(x), 'value', plist, None)
        #print plist
        print compact(plist, '')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of calling codes for all countries(the phone number prefixes), I
I'd like to get a list of all ABContacts that have a phone number
I have a phone number field that can have lots of different characters such
My question is easier to explain with an example: I have a phone number
Lets say I have a Phone number my classes need to validate and keep
I am trying to get all contacts that have a phone number, and record
I have phone number. Is there any way to check whether the phone number
I have a phone number I want to match against a regular expression. The
If I have a phone number, and the owner of the number Has a
I have to call phone number and detect if the modem at the opposite

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.