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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:53:30+00:00 2026-05-27T21:53:30+00:00

I am generating text using this : for i in xrange(100): sys.stdout.write(alphabet[bisect.bisect(f_list, random.random()) –

  • 0

I am generating text using this :

for i in xrange(100):
    sys.stdout.write(alphabet[bisect.bisect(f_list, random.random()) - 1])

i get output that looks like this:

fnhtlr hhub  del tn eleo s d  nerowepeldhoantah yf  tr e saetenwgkoyears 
oenooe urbmhonnrniwc iasseb

and I would like to know how to store the output as TEXT, not a list, so that i can use fd.inc(word) on it. I am basically trying to plot Zipf’s law with my random output.

if I use this :

text1 = [alphabet[bisect.bisect(f_list, random.random())] for i in xrange(300)]

my output is stored as a list and fd doesn’t work on it, as it considers each character to be a separate word.

for word in text1:
    fd.inc(word)
print fd
<FreqDist: ' ': 1776, 'e': 1008, 'a': 752, 't': 750, 'n': 604, 'i': 586,
 'o': 556, 'h': 542, 's': 528, 'r': 478, 'l': 388, 'd': 312, 'u': 242, 
'm': 202, 'w': 192, 'g': 172, 'b': 152, 'p': 152, 'f': 150, 'c': 148, 'y': 120,
 'k': 90, 'v': 66, 'q': 12, 'z': 10, 'x': 8, 'j': 4>

I would like each sequence of letters separated by a space to be considered as a word, i.e. for the output to be considered as text.

Thank you for your help!

  • 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-27T21:53:31+00:00Added an answer on May 27, 2026 at 9:53 pm

    Try this:

    text1 = ' '.join([alphabet[bisect.bisect(f_list, random.random())] for i in xrange(300)])
    

    As to add more detail: ' '.join(list) is the pythonic way of joining a list to a string. The ' '-part says that it should be joined with a whitespace. If you for example would join it with a comma it would be ',' instead.

    Or you could even skip the brackets like this:

    text1 = ' '.join(alphabet[bisect.bisect(f_list, random.random())] for i in xrange(300))
    

    Maybe you want to join the list completly without anything between the charachters. In that case the solution is using join like this:

    text1 = ''.join([alphabet[bisect.bisect(f_list, random.random())] for i in xrange(300)])
    

    One more thing thought. What happens if you change your last sample snippet in your question to:

    for word in text1.split():
        fd.inc(word)
    print fd
    

    This will split again after joining, but this time it will split on word and not characters (so keep the join also).

    Final word

    Since the issue has been solved I want to just explain what those things mean:

    ''.join(list) – This means taking the original list which is separated by every charachter and make a string out of it.

    string.split() – This means to make a list of it again (which fd.inc whatever that is apperently want one) but make this one separated by word and not charachter like the original list.

    Also, I would recommend you looking on some Python basics which will help you in the future 🙂 This is a great series of videos: http://www.youtube.com/watch?v=tKTZoB2Vjuk

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm generating text using this font server-side, but I've been told Vista and
I'm generating an image out of text using php. My code works perfectly on
I'm looking for tools for generating random but realistic text. I've implemented a Markov
Playing around with generating text randomly with each page refresh using php. Is there
What I tried to do is generating a text file on ASP.Net using C#.
Well my situation is like this: I am generating a report as a text
I am generating events on fullCalendar with this code <script type=text/javascript> $(document).ready(function() { $('#calendar').fullCalendar({
I am very new to generating an speech using some input text. I tried
I am using com.lowagie.text.FontFactory in generating a PDF file and am trying to use
I am foxed by this... I am generating a slide show using the jQuery

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.