I have a question.

Asked 2 years ago, Updated 2 years ago, 26 views

1 2 3 4 5 6         
6 7 8 9 10 11
12 13 14 15 16

Data of this type

I'd like to divide 6 pieces and make one that doesn't print out if there is 1.

6 7 8 9 10 11
12 13 14 15 16 

I want to make it print out.

What should I do?

python

2022-09-20 15:49

1 Answers

Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> data = [ 1,2,3,4,5,6, 6,7,8,9,10,11, 12,13,14,15,16 ]
>>> for i in range(0, len(data), 6):
    print(data[i:i+6])


[1, 2, 3, 4, 5, 6]
[6, 7, 8, 9, 10, 11]
[12, 13, 14, 15, 16]
>>> for i in range(0, len(data), 6):
    data6 = data[i:i+6]
    if 1 not in data6:
        print(data6)


[6, 7, 8, 9, 10, 11]
[12, 13, 14, 15, 16]
>>> for i in range(0, len(data), 6):
    data6 = data[i:i+6]
    if 1 not in data6:
        print(*data6, sep=" ")


6 7 8 9 10 11
12 13 14 15 16
>>> 


2022-09-20 15:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.