Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python – join propositions

I have an list of strings which illustrate propositions. E.g.

L = ['(A∧B)', 'A', 'B']

My aim is to join each element with the string ‘∧’ and brackets "()", which results in following string:

aim = "(((A ∧ B) ∧ A) ∧ B)"

is their a simple method to do that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use reduce from functools module:

from functools import reduce

aim = reduce(lambda l, r: f"({l} ^ {r})", L)
print(aim)

# Output
(((A∧B) ^ A) ^ B)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading