##### Make Groups with the List Elements
 Make Groups with the List Elements quest Wafer-Thin Wafer Posts: 80 Threads: 36 Joined: Nov 2020 Reputation: Jul-11-2021, 08:35 AM Hello, I have pairs list: `pairs=[[A,B],[C,D],[Z,X]]`And I have also a queue list which is includes: `queue =[A,B,C,D,E,F,G,H,I,Z,X,J,K,L]`And I want to make groups from list queue and this groups should be exactly the same with elements of pairs. I mean, I want to make [A,B] [C,D] [Z,X] groups if these elements[A,B,C,DZ,X] exist inside the queue list. Note: here A,B,C,D,Z,X are just an example. In my code they correspond objects How can I do that? Reply Posts: 2,013 Threads: 35 Joined: Sep 2016 Reputation: Jul-11-2021, 09:52 AM loop over the pairs, check if both pair items are in the list of queue items, if they are add the pair to a new list quest likes this post Reply Posts: 1,835 Threads: 8 Joined: Jun 2018 Reputation: Jul-11-2021, 09:58 AM (Jul-11-2021, 08:35 AM)quest Wrote: How can I do that? Figuring out solution and writing code. Lot of ambiguity in problem description, but there is data structure in Python called sets which primary purpose is: Quote:A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. So one can write something like that: ```>>> names = ['spam', 'ham', 'eggs', 'bacon'] >>> pairs = [['ham', 'bacon'], ['spam', 'foo']] >>> for pair in pairs: ... print(set(pair).issubset(names)) ... True False``` quest likes this post I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. Reply

 Possibly Related Threads… Thread Author Replies Views Last Post ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 804 May-17-2022, 11:38 AM Last Post: Larz60+ Ldap Search for finding user Groups ilknurg 1 575 Mar-11-2022, 12:10 PM Last Post: DeaD_EyE Why am I getting list elements < 0 ? Mark17 8 1,660 Aug-26-2021, 09:31 AM Last Post: naughtyCat Looping through nested elements and updating the original list Alex_James 3 1,075 Aug-19-2021, 12:05 PM Last Post: Alex_James Extracting Elements From A Website List knight2000 2 1,026 Jul-20-2021, 10:38 AM Last Post: knight2000 I cannot delete and the elements from the list quest 4 1,779 May-11-2021, 12:01 PM Last Post: perfringo List of lists - merge sublists with common elements medatib531 1 2,197 May-09-2021, 07:49 AM Last Post: Gribouillis Find Common Elements in 2 list quest 4 1,609 Apr-14-2021, 03:57 PM Last Post: quest Sorting Elements via parameters pointing to those elements. rpalmer 3 1,589 Feb-10-2021, 04:53 PM Last Post: rpalmer Group List Elements according to the Input with the order of binary combination quest_ 19 3,570 Jan-28-2021, 03:36 AM Last Post: bowlofred

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020