A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Python program to interleave two given list into another list randomly
Q:

Write a Python program to interleave two given list into another list randomly

0

Write a Python program to interleave two given list into another list randomly.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import random
def randomly_interleave(nums1, nums2):
    result =  [x.pop(0) for x in random.sample([nums1]*len(nums1) + [nums2]*len(nums2), len(nums1)+len(nums2))]
    return result
nums1 = [1,2,7,8,3,7]
nums2 = [4,3,8,9,4,3,8,9]
print("Original lists:") 
print(nums1)
print(nums2)
print("\nInterleave two given list into another list randomly:")
print(randomly_interleave(nums1, nums2))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now