How can I combine a conditional with a for loop in Python?

后端 未结 3 916
囚心锁ツ
囚心锁ツ 2021-01-22 01:08

I have a simple example I\'ve drawn up. I thought it was possible to combine if statements and for loops with minimal effort in Python. Given:

sublists = [numb         


        
3条回答
  •  攒了一身酷
    2021-01-22 01:36

    if you want to filter out all the empty sub list from your original sub lists, you will have to do something like below. this will give you all the non empty sub list.

    print([sublist for sublist in sublists if sublist])
    

    *edited for syntax

提交回复
热议问题