Write a python function to generate a random combination from user provided list and user specified length.
Topic: Write a python function to generate a random combination from user provided list and user specified length.
Solution
import itertools def get_random_combination(input_list, combination_length): if(len(input_list) < combination_length): print("Requested combination length less than length of list") return combination_list = list(itertools.combinations(input_list, combination_length)) return random.sample(combination_list, 1)
List all Python Programs