469,282 Members | 1,743 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

create words of various lengths

"X-No-Archive: yes"

what I am looking for is

1. To create a list of different words of various lengths(1-15) using
A-Z,a-z,0-9 and punctuations.Basically anything that could be found on
a text document.

2. The words formed need not be meaningful .FOr example 'ajf' or
'fcjgdtfhbs' or even 'gfdew!' or '#bang.' would be a valid entry in the
list.

3.So I am looking for a random set of words of sizes 1 to 15.The proble
might be the time complexity. I inderstand that there would be too many
permutations.

Jul 19 '05 #1
9 1965
su*******@gmail.com wrote:
"X-No-Archive: yes"

what I am looking for is

1. To create a list of different words of various lengths(1-15) using
A-Z,a-z,0-9 and punctuations.Basically anything that could be found on
a text document.

2. The words formed need not be meaningful .FOr example 'ajf' or
'fcjgdtfhbs' or even 'gfdew!' or '#bang.' would be a valid entry in the
list.

3.So I am looking for a random set of words of sizes 1 to 15.The proble
might be the time complexity. I inderstand that there would be too many
permutations.


So why don't you take one step back and tell us what you think you need
this list *for*? We might be able to come up with feasible alternatives.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #2
Hi Robert,
At first I thought it would be an interesting thing to have a little
swift module to create a database of all words in the dictionary.But
then I thought y just the words in the dictionary? y not all possible
words like 'and' and 'adn'. Just was inspired with the little idea of
if its an 'and' or 'adn' when u read it in a combination of other words
you read it as 'and' itself.

"nohting spceific wsa jsut plyaing around wtih ideas "

Jul 19 '05 #3
su*******@gmail.com wrote:
what I am looking for is

1. To create a list of different words of various lengths(1-15) using
A-Z,a-z,0-9 and punctuations.Basically anything that could be found on
a text document.

2. The words formed need not be meaningful .FOr example 'ajf' or
'fcjgdtfhbs' or even 'gfdew!' or '#bang.' would be a valid entry in the
list.

3.So I am looking for a random set of words of sizes 1 to 15.The proble
might be the time complexity. I inderstand that there would be too many
permutations.


how many words do you need? the following bruce-force solution
doesn't take that long to run on my machine, and the resulting words
are guaranteed to be almost entirely meaningless ;-)

import string
from random import choice, randint, shuffle

alphabet = string.letters + string.digits + "%&!?#"

words = {}

while len(words) < 10000:
words["".join(choice(alphabet) for i in range(randint(1,15)))] = None

words = words.keys()
shuffle(words)

to generate text from this, reshuffle the word list after you've written
a number of words. (or you could slice off a random number of words
and run the loop again, at random intervals. or something.)

the character and word distribution will have no similaries with real text,
of course, but maybe that doesn't matter.

</F>

Jul 19 '05 #4
su*******@gmail.com wrote:
Hi Robert,
At first I thought it would be an interesting thing to have a little
swift module to create a database of all words in the dictionary.
Okay, take one more step back. Why is it interesting to have such a
dictionary? How do you intend to use it?

Having answered those questions, why is it interesting to extend this
with meaningless collections of symbols?

No one can offer you a better method if we don't have a metric to judge
whether a method is "better" than another.
But
then I thought y just the words in the dictionary? y not all possible
words like 'and' and 'adn'. Just was inspired with the little idea of
if its an 'and' or 'adn' when u read it in a combination of other words
you read it as 'and' itself.

"nohting spceific wsa jsut plyaing around wtih ideas "


Well, that's a somewhat different problem.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #5
no specific number of words.
and I get a syntax error on line:
words["".join(choice(alphabet) for i in range(randint(1,15)))] = None


Jul 19 '05 #6
this works

while len(words) < 10000:
wd = ""
for i in ["".join(choice(alphabet)) for i in
range(randint(1,15))]:
wd += i
words[wd] = None

anyway Thanks for that this is exactly what i need..

Jul 19 '05 #7
su*******@gmail.com wrote:
no specific number of words.
anything between one and a gazillion, you mean? having some idea of
the upper bound helps when chosing what algorithm/database/computer
to use...
and I get a syntax error on line:
words["".join(choice(alphabet) for i in range(randint(1,15)))] = None


so what's your excuse for not using a recent version of Python? ;-)

if you're stuck with an older version,

words["".join([choice(alphabet) for i in range(randint(1,15))])] = None

should work.

</F>

Jul 19 '05 #8
:) the reason for me not upgrading my python is I am waiting for
version of Numeric to be released for python 2.4 .The stable version of
Numeric is only release for windows and not Linux I guess the last time
i checked. which i use a lot .

Anyway thanks

Jul 19 '05 #9
su*******@gmail.com wrote:
:) the reason for me not upgrading my python is I am waiting for
version of Numeric to be released for python 2.4 .The stable version of
Numeric is only release for windows and not Linux I guess the last time
i checked. which i use a lot .


Install from source. It works just fine. Numeric will never be released
"just for Windows."

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jeff Thies | last post: by
10 posts views Thread by Aaron | last post: by
4 posts views Thread by sumedh..... | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.