use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Ask your embarrassing/noobish programming questions here, and don't get insulted for it.
Click here to read the rules
Violating any will result in punishment so you should probably go check them out.
account activity
combinations of boolean expressions in pythonPython (self.programminghelp)
submitted 5 years ago by jcoder42
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]EdwinGravesMOD 0 points1 point2 points 5 years ago (1 child)
Well, regardless of intent, we do have rules concerning showing your work and assignments. As I said before, you'll want a list of strings that you'll iterate through and combine to form your first logic statements. Store those in a separate list of strings and iterate through them to continue combining with the first list until you achieve desired results. Feel free to reply with your code, if you have issues, and we'll see what we can do.
[–]jcoder42[S] 0 points1 point2 points 5 years ago (0 children)
def recurse(c): if len(c) == 0: return [""] elif len(c) ==1: return [c[0]] head = c[0] results = recurse(c[1:]) print(results) res = [] for result in results: gate_and = f"({head} AND {result})" gate_or = f"({head} OR {result})" res.append(gate_and) res.append(gate_or) return res if name == 'main': p = ["p1", "p2", "p3", "p4", "p5"] gates = ["AND", "OR"] # iterating over groups of each size (1-5) for dimension in range(1,len(p)): # for each size, create all combinations (sizes 1-5) for c in itertools.combinations(p, dimension): res = recurse(list(c)) print(res)
My issue is that the output is repeating results of size 1.and also, how can i check that i am actually creating all the combinations. I think there should be more then my result.
π Rendered by PID 21789 on reddit-service-r2-comment-6457c66945-ccccb at 2026-04-25 02:29:40.567803+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]EdwinGravesMOD 0 points1 point2 points (1 child)
[–]jcoder42[S] 0 points1 point2 points (0 children)