Randomly Shuffle Words Function

  • Share this:

Code introduction


This function takes a list of words as input and returns a new list with the words in a random order.


Technology Stack : random.sample

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def shuffle_words(words):
    """
    将传入的单词列表随机打乱顺序。
    """
    shuffled_words = random.sample(words, len(words))
    return shuffled_words