简体   繁体   中英

Python Enthought Canopy Word Scrambler

import random  

def word_scrambler(word):        
    a = word[1] 
    b = word[2]
    c = word[3]
    d = word[4]
    e = word[5]
    f = word[6]
    g = word[7]
    h = word[8]
    letterzz = [a,b,c,d,e,f,g]
    letterz = [a,b,c,d,e,f,g,h]
    letter = [a,b,c,d,e,f]
    lette = [a,b,c,d,e]
    lett = [a,b,c,d]
    let = [a,b,c]
    le = [a,b]
    l = [a]
    i = random.choice(l)
    j = random.choice(le)
    k = random.choice(let)
    l = random.choice(lett)
    m = random.choice(lette)
    n = random.choice(letter)
    o = random.choice(letterz)
    p = random.choice(letterzz)

    return i+j+k+l+m+n+o+p

What I am trying to do is create a word scrambler that will scramble an inputted word from the function. I am not sure how to make it choose a random letter only once from each section of the word inputted. So like [a,b,c,d,e,f,g] and make it pick g only once and then it won't pick g again in the next search, and have it do that until it has used all the letters from the inputted word to make a random string.

import random  

def word_scrambler(word):
    letter_list = list(word)
    random.shuffle(letter_list)
    return ''.join(letter_list)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM