Python Forum
Need to parse a list of boolean columns inside a list and return true values - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Need to parse a list of boolean columns inside a list and return true values (/thread-35996.html)



Need to parse a list of boolean columns inside a list and return true values - Python84 - Jan-08-2022

Hi All,

Need to do this only when whole expression is true

Example 1: List -> [[A] OR [B]]
True value: A
o/p expected : [A]

Example 2: List -> [[[A] AND [B]] OR [[C] AND [D]]
True values: A,B,C,D
o/p expected : [A-B-C-D]

Example 3: List -> [[[A] AND [B]] OR [[C] AND [D]]
True values: A,B
o/p expected : [A-B]

Example 4: List -> [[[A] AND [B]] OR [[C] AND [[D] OR [E] OR [F]]]]
True values: A,B,C,D,E,F
o/p expected : [A-B-C-D-E-F]

Example 5: List -> [[[A] AND [B]] OR [[C] AND [[D] OR [E] OR [F]]]]
True values: A,B,C,D
o/p expected : [A-B-C-D]


Example 6: List -> [[[A] AND [B]] OR [[C] AND [[D] OR [E] OR [F]]]]
True values: A,B,C,D
o/p expected : [A-B-C-D]

Example 7: List -> [[[A] AND [B]] OR [[C] AND [[D] OR [E] OR [F]]]]
True values: C,D,E
o/p expected : [C-D-E]

Example 8: List -> [[[A] AND [B]] OR [[C] AND [[D] OR [E] OR [F]]]]
True values: A,C
Non true values: B,D,E,F
o/p expected : [] as whole expression is not true

Input is List of list with columns from a pyspark dataframe containing true or false values. Output can be for example ['A'-'B'-'C'-'D'] as well ,basically need to grab the true values in a '-' delimited pattern ,eventually [[A] OR [B]] converts to ((A) OR (B)) in expr for pyspark and is evaluated as true or false ,I want to grab all true columns which made this whole expression true.
Any pointers ,pseudo code will guide me correct direction.

Thanks
P


RE: Need to parse a list of boolean columns inside a list and return true values - Larz60+ - Jan-08-2022

We are not here to write code for you, we are here to help you write the code yourself, please see the following rule: https://python-forum.io/misc.php?action=help&hid=52

Please make an attempt at writing the code, and ask questions when you run into difficulty.


RE: Need to parse a list of boolean columns inside a list and return true values - Python84 - Jan-08-2022

(Jan-08-2022, 09:22 AM)Larz60+ Wrote: We are not here to write code for you, we are here to help you write the code yourself, please see the following rule: https://python-forum.io/misc.php?action=help&hid=52

Please make an attempt at writing the code, and ask questions when you run into difficulty.

Hi Moderator

I specifically asked for "Any pointers ,pseudo code will guide me correct direction" not the code ,apologies if it felt like that.
Please help fellow new Comer in python with guidance to solve this problem


RE: Need to parse a list of boolean columns inside a list and return true values - Larz60+ - Jan-09-2022

my apologies, sometimes scan too fast.


RE: Need to parse a list of boolean columns inside a list and return true values - Python84 - Jan-09-2022

(Jan-09-2022, 02:34 AM)Larz60+ Wrote: my apologies, sometimes scan too fast.

No problem,can someone help me out in right direction here,this seems like a nice problem to solve Big Grin