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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:59:18+00:00 2026-05-24T06:59:18+00:00

I’m trying to make a simple dict generator. It works but it isn’t very

  • 0

I’m trying to make a simple dict generator. It works but it isn’t very functional yet.

I’d like to improve it by being able to change the max size of the output without touching the code.

letr='abcdefghijklmnopqrstuvwxyz'
for i in range(len(letr)):
    t=letr[i]
    print t
    for t2 in letr:
        print t+t2
        for t3 in letr:
            print t+t2+t3
            for t4 in letr:
                print t+t2+t3+t4
                for t5 in letr:
                    print t+t2+t3+t4+t5
  • 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-24T06:59:20+00:00Added an answer on May 24, 2026 at 6:59 am
    import itertools
    
    def dict_gen(n):
        letr = 'abcdefghijklmnopqrstuvwxyz'
        return itertools.chain(''.join(j) for i in range(n) 
                               for j in itertools.product(letr, repeat=i+1))
    

    Usage:

    for word in dict_gen(n):  # replace n with the max word length you want
        print word
    

    Unlike some of the other answers this will include duplicates like your example (‘aa’, ‘bb’, etc).

    dict_gen() will return a generator, but you can always just pass it into list() if you need to access elements by index:

    >>> words = list(dict_gen(5))
    >>> len(words) == 26 + 26**2 + 26**3 + 26**4 + 26**5  # verify correct length
    True
    >>> words[20:30]  # transition from one letter to two letters
    ['u', 'v', 'w', 'x', 'y', 'z', 'aa', 'ab', 'ac', 'ad']
    >>> words[-10:]   # last 10 elements
    ['zzzzq', 'zzzzr', 'zzzzs', 'zzzzt', 'zzzzu', 'zzzzv', 'zzzzw', 'zzzzx', 'zzzzy', 'zzzzz']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.