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
  remove duplicates from dicts with list values wardancer84 27 864 May-27-2024, 04:54 PM
Last Post: wardancer84
  what to return for an empty list Skaperen 2 259 May-24-2024, 05:17 PM
Last Post: Skaperen
  Strange behavior list of list mmhmjanssen 3 455 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  Converting column of values into muliple columns of counts highland44 0 328 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,947 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Copying the order of another list with identical values gohanhango 7 1,307 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,375 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Need to return 2 values from 1 DF that equals another DF cubangt 5 718 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,370 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,335 Jun-09-2023, 04:57 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