1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Word Order Program Help Needed

Discussion in 'General Scripting Chat' started by SaraJ, Oct 13, 2010.

  1. SaraJ

    SaraJ Junior Member

    Joined:
    Jun 11, 2010
    Messages:
    172
    Likes Received:
    71
    Ok, I hope I can make some sense when I type this out.

    I'm looking for a program or something that I can use that will reorder words in a phrase for me.

    For example, If I had a 4 word phrase I would want to put it into the program and have it spit out stuff like...

    word 1
    word 2
    word 3
    word 4
    word 1 word 2
    word 1 word 3
    word 1 word 4
    word 2 word 1
    word 2 word 3........

    And every 2, 3 ,4 word possible combination of that word phrase.

    I really don't know how to do this but I'm sure someone does here.

    Please help.

    Sara
     
  2. RiskyShift

    RiskyShift Newbie

    Joined:
    Sep 16, 2010
    Messages:
    19
    Likes Received:
    3
    I don't know what language you want this in? It's very easy in Python:

    Code:
    import itertools
    
    phrase = "let's permute a phrase"
    
    words = phrase.split(' ')
    for i in xrange(1, len(words)+1):
        for permutation in (itertools.permutations(words, i)):
            print ' '.join(permutation)
    
    If you run that you get the output:

    Code:
    let's
    permute
    a
    phrase
    let's permute
    let's a
    let's phrase
    permute let's
    permute a
    permute phrase
    a let's
    a permute
    a phrase
    phrase let's
    phrase permute
    phrase a
    let's permute a
    let's permute phrase
    let's a permute
    let's a phrase
    let's phrase permute
    let's phrase a
    permute let's a
    permute let's phrase
    permute a let's
    permute a phrase
    permute phrase let's
    permute phrase a
    a let's permute
    a let's phrase
    a permute let's
    a permute phrase
    a phrase let's
    a phrase permute
    phrase let's permute
    phrase let's a
    phrase permute let's
    phrase permute a
    phrase a let's
    phrase a permute
    let's permute a phrase
    let's permute phrase a
    let's a permute phrase
    let's a phrase permute
    let's phrase permute a
    let's phrase a permute
    permute let's a phrase
    permute let's phrase a
    permute a let's phrase
    permute a phrase let's
    permute phrase let's a
    permute phrase a let's
    a let's permute phrase
    a let's phrase permute
    a permute let's phrase
    a permute phrase let's
    a phrase let's permute
    a phrase permute let's
    phrase let's permute a
    phrase let's a permute
    phrase permute let's a
    phrase permute a let's
    phrase a let's permute
    phrase a permute let's
    
    Is that what you're after?
     
    • Thanks Thanks x 1
  3. SaraJ

    SaraJ Junior Member

    Joined:
    Jun 11, 2010
    Messages:
    172
    Likes Received:
    71
    Thank you.

    I have Python on my computer and can run this in a terminal.

    It will serve the purposes I was looking for.

    Thank you very much.

    :D