Merging and Shuffling Two Lists Function

  • Share this:

Code introduction


This function takes two lists as arguments, merges them, shuffles the combined list, and returns the shuffled list.


Technology Stack : random

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def shuffle_list(arg1, arg2):
    if not isinstance(arg1, list) or not isinstance(arg2, list):
        raise TypeError("Both arguments must be lists.")
    
    shuffled_list = arg1 + arg2
    random.shuffle(shuffled_list)
    return shuffled_list                
              
Tags: