Shuffling Words with pytest#s Random Module

  • Share this:

Code introduction


This function takes a list of words as input and shuffles the order of the words in the list using the random.sample function from pytest's monkeypatch module.


Technology Stack : pytest, random.sample

Code Type : Function

Code Difficulty : Intermediate


                
                    
def shuffle_words(words):
    import random
    import pytest

    # Shuffle the list of words using pytest's random module
    shuffled_words = pytest.monkeypatch.random.sample(words, len(words))
    return shuffled_words