Help - just a few lines of code needed

L

lory88

Hi

I hope someone can help me out with a very SIMPLE program
about whole string permutations. That is: given a list of strings,
the required outcome is a complete set of all their possible
permutations.
It's like character permutations of a string, but this time it is
whole strings instead of single characters that have to be permuted.

I need this because I don't remember exactly the password to open
my zipped archives, but i do remember the bits of strings
that made up the long passphrase.

Could someone kindly write a simple program that, after reading a set
of
strings contained in a .txt file (one string on each line),
produces as output another .txt file containing all the possible
permutations/combinations of those strings.

For example, the text file with the set of strings may contain:

HOUSE
jolly
---
0&
99


and the output file contains:

HOUSE
HOUSEjolly
HOUSE---
HOUSE0&

and so on...
....with the word combinations growing extensively,
so as to exhaust all the possibilities:

e.g.

---99jolly0&
jolly0&---99HOUSE

etc. etc.

Unfortunately I am not able to program it myself, so
I would appreciate if someone could write this piece of
software, compile it (for DOS or Windows) and send the .exe file to:

lory88 at gmail . com


I thank you all in advance.

Lory
 
J

johnzenger

There is some fine permutation code in the cookbook. Take a look at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465 .

You can easily code something like:

# xcombinations from the cookbook
def xcombinations(items, n):
if n==0: yield []
else:
for i in xrange(len(items)):
for cc in xcombinations(items[:i]+items[i+1:],n-1):
yield [items]+cc

wordlist = ['HOUSE','jolly','---','0&','99']

for i in xrange(1, len(wordlist)+1):
for g in xcombinations(wordlist, i):
print "".join(g)

Unfortunately I am not able to program it myself, so
I would appreciate if someone could write this piece of
software, compile it (for DOS or Windows) and send the .exe file to:

lory88 at gmail . com

Meet us halfway, here. At least install Python.

Also, it's a dangerous world out there. Don't run .exe s sent to you
by people you don't know.
 
C

Cameron Laird

There is some fine permutation code in the cookbook. Take a look at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465 .

You can easily code something like: .
.
.

Meet us halfway, here. At least install Python.

Also, it's a dangerous world out there. Don't run .exe s sent to you
by people you don't know.

All true.

This situation rather intrigues me at what I'll call a
managerial level. I'm sympathetic to the possibility
that Lory might have a life where compilation and
script-launching and our other commonplaces are very
remote; I salute him or her for recognizing that
string permutation is indeed a feasible goal for a
simple .EXE. I know *I* sometimes am in the situation
of not having a useful Windows installation of a C
compiler, or adequate Java environment, or ..., and I
lean on the kindnesss o strangers at least temporarily.

At the same time, there's little incentive for
comp.lang.python to take on the burden of application
development for transients in Pythonia. Lory, we can
walk you through the "at least install Python" part Mr.
Zenger mentions above in ten minutes; truly, it'll take
less time than it would to negotiate delivery of a
special-purpose executable for you.

I remain curious: how'd you come to Python for your
need? Is there some particular reason--most likely,
that you're a potential Python student yourself--that
we should help you? Is there a reason--that this is
an assignment you're to do on your own?--that we should
*not*?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top