- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – All replacement combination from other list
When it is required to get the replacement combination from the other list, the ‘combinations’ method and the ‘list’ method is used.
Below is a demonstration of the same
from itertools import combinations my_list = [54, 98, 11] print("The list is :") print(my_list) replace_list = [8, 10] my_result = list(combinations(my_list + replace_list, len(my_list))) print("The result is :") print(my_result)
The list is : [54, 98, 11] The result is : [(54, 98, 11), (54, 98, 8), (54, 98, 10), (54, 11, 8), (54, 11, 10), (54, 8, 10), (98, 11, 8), (98, 11, 10), (98, 8, 10), (11, 8, 10)]
The required packages are imported into the environment.
A list is defined and is displayed on the console.
Another replace list is defined.
The 'combinations' method is used to concatenate the original list, the replace list, and the length of the original list.
This is converted to a list.
This is assigned to a variable.
The result is displayed on the console.
- Minimize Cost with Replacement with other allowed in C++
- Python prorgam to remove duplicate elements index from other list
- Python – Combine list with other list elements
- List comprehension and ord() in Python to remove all characters other than alphabets
- Python – Test if elements of list are in Min/Max range from other list
- Switch Case in Python (Replacement)
- Combination Sum in Python
- Python program to get all pairwise combinations from a list
- Permutation and Combination in Python?
- Python – Maximum of K element in other list
- Python Program to Extract Strings with at least given number of characters from other list
- Python – All occurrences of Substring from the list of strings
- Python – Filter all uppercase characters from given list of tuples
- Check if one list is subset of other in Python
- Python - Most common Combination in Matrix