python build a dynamic growing truth table

后端 未结 7 2047
失恋的感觉
失恋的感觉 2021-02-07 04:36

My question is simple: \"how to build a dynamic growing truth table in python in an elegant way?\"

for n=3

for p in False, True:
    for q in False, Tru         


        
7条回答
  •  故里飘歌
    2021-02-07 04:41

    who here likes raw 1-liners?

    >>> truthtable = lambda n: [[(v>>i)&1 for i in range(n-1,-1,-1)] for v in range(1<0 else [[]]
    

    100% tested and working.
    (can't copy/paste result, or above code, cause I'm on a phone for Internet)

提交回复
热议问题