output - Format the print statement in Python -


i have script takes in txt file list of attributes go input program. each attribute, prints out attribute name if satisfies conditions of script. however, each attribute may satisfied multiple times , output prints many times. i'd now:

condition 1 satisfied a,b,c,d condition 2 satisfied a,b condition 3 satisfied b,d 

how do this? current output looks like

a condition 3 not satisfied b b b condition 1 not satisfied c condition 2 not satisfied c c d condition 2 not satisfied d d 

how (in pseudo python code)

import collections result = collections.defaultdict(list) attr in [a, b, c, d]:   cond in [condition1, condition2, ...]:      if attr satisfies cond:         result[cond].append(attr)  print result 

output:

{cond1: [a, b], cond2: [a], cond3: [c,d], ...} 

i'm not sure want. haven't stated (enough) input looks , want output.


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -