1

I have got the following list:

lst = [['a','!b'], ['91','q'], ['!t','3','p']]

I want the following as output:

test = a and !b or 91 and q or !t and 3 and p

The individual literals in the sublist is made into a single literal and joined using 'and' and then the sublists are joined together using 'or'

I tried the following, can someone correct my code?

   def output(self):
      temp = ['and'.join(sublist[i]) for i in sublist]
      test = ['or'.join(sublist) for sublist in self.lst]
      return self.test

1 Answer 1

5

All at once:

def output(lst):
    return " or ".join(" and ".join(s) for s in lst)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.