Python Forum
Need to parse a list of boolean columns inside a list and return true values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to parse a list of boolean columns inside a list and return true values
#1
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
Reply
#2
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.
Reply
#3
(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
Reply
#4
my apologies, sometimes scan too fast.
Reply
#5
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 91 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Converting column of values into muliple columns of counts highland44 0 205 Feb-01-2024, 12:48 AM
Last Post: highland44
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,442 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Copying the order of another list with identical values gohanhango 7 1,062 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Need to return 2 values from 1 DF that equals another DF cubangt 5 593 Oct-21-2023, 02:45 PM
Last Post: deanhystad
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,091 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,083 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 753 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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