Given a Matrix, for groups according to list elements, i.e each group should contain all elements from List.
Input : test_list = [[2, 6], [7, 8], [1, 4]], check_list = [1, 2, 4, 6]
Output : [[7, 8], [[1, 2], [4, 6]]]
Explanation : 1, 2, 4, 6 elements rows are grouped.
Input : test_list = [[2, 7], [7, 8], [1, 4]], check_list = [1, 2, 4, 6]
Output : [[2, 7], [7, 8], [1, 4]]
Explanation : No grouping possible.
Method : Using loop + list comprehension + Try-Except
In this, for each row in matrix, get elements missing from list, after getting elements, match with each row if we can find missing elements, if found, the new group is made.
The original list is : [[4, 6], [1, 2], [2, 6], [7, 8], [1, 4]] The Grouped rows : [[[1, 4], [2, 6]], [7, 8], [[1, 2], [4, 6]]]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python - Convert List to key-value list by prefix grouping
- Python | Consecutive elements grouping in list
- Python | Frequency grouping of list elements
- Python - Inter Matrix Grouping
- Python | Binary element list grouping
- Python | Grouping similar substrings in list
- Python | Grouping list values into dictionary
- Python | Identical Consecutive Grouping in list
- Python - Value nested grouping on List
- Python - Summation Grouping in Dictionary List
- Python - Paired elements grouping
- Python | Grouping dictionary keys by value
- Python | K Division Grouping
- Python | Identical Strings Grouping
- Python - Case Insensitive Strings Grouping
- Python - Frequency Grouping Dictionary
- Python - Vertical Grouping Value Lists
- Python - Cross tuple summation grouping
- Grouping Rows in pandas
- Grouping Categorical Variables in Pandas Dataframe
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.