简体   繁体   中英

Print new line each array index in a loop reach certain number

I have this array (as an example of my problem) :

[0.8067, 0.7152, 0.4551, 0.7519, 0.3419, 0.7161, 0.3793, 0.6859, 0.4205, 0.5129, 0.5534, 0.5995, 0.4999, 0.5136, 0.8194, 0.4855, 0.6822, 0.4924, 0.5359, 0.4083, 0.5078, 0.7260, 0.6876, 0.7033, 0.5777, 0.4515, 0.5460,0.5842, 0.7296, 0.7570, 0.4579, 0.3252, 0.4683, 0.3646, 0.3220, 0.4150,0.3263, 0.6402, 0.3184, 0.7087, 0.2958, 0.5384, 0.5462, 0.3933, 0.2963,0.6883, 0.4766, 0.5430, 0.4943, 0.2810, 0.4785, 0.5618, 0.6941, 0.4943,0.3793, 0.7629, 0.6058, 0.6419, 0.4902, 0.3158, 0.7923, 0.7335, 0.5624,0.5390, 0.5337, 0.8333, 0.7519, 0.6591, 0.5301, 0.3020, 0.8187, 0.8084,0.3412, 0.7912, 0.6240, 0.4296, 0.4908, 0.6560, 0.7366, 0.5219, 0.8128,0.3683, 0.6037, 0.4570, 0.3640, 0.4717, 0.5948, 0.6294, 0.8222, 0.7323,0.4344, 0.4371, 0.5013, 0.2913, 0.4335, 0.4046, 0.6788, 0.5917, 0.8369,0.8983, 0.3981, 0.8857, 0.4309, 0.6197, 0.7020, 0.3666, 0.5837, 0.3259,0.7193, 0.3719, 0.7098, 0.4088, 0.5421, 0.5039, 0.3664, 0.5499, 0.8648, 0.3217, 0.7696, 0.5970, 0.4611, 0.3465, 0.6396, 0.6688, 0.5773, 0.7444,0.7232, 0.5695, 0.5801, 0.5218, 0.8099, 0.6983, 0.5733, 0.3286, 0.6736, 0.6470, 0.9196, 0.7589, 0.7610, 0.8454, 0.6261, 0.6229, 0.7600, 0.5022,0.3035, 0.5229, 0.5353, 0.4962, 0.8466, 0.1817, 0.5271, 0.6928, 0.7898,0.4182, 0.5234, 0.4112, 0.4812, 0.7522, 0.4209, 0.7217, 0.6545, 0.6954,0.3139, 0.5253, 0.5467, 0.3606, 0.6640, 0.7399, 0.7965, 0.5742, 0.5729,0.6213, 0.7981, 0.5613, 0.4904, 0.7292, 0.5686, 0.8421, 0.7316, 0.6408,0.6550, 0.3902, 0.5353, 0.5459, 0.4035, 0.3390, 0.4407, 0.7370, 0.4466,0.4029, 0.8216, 0.4862, 0.7136, 0.3544, 0.7967, 0.2909, 0.4384, 0.5505,0.6768, 0.5122, 0.6042, 0.5240, 0.4299, 0.3714, 0.6224, 0.6549, 0.7901,0.7289, 0.7580, 0.5656, 0.7841, 0.7520, 0.8379, 0.4449, 0.4860, 0.6904,0.7279, 0.6378, 0.4493, 0.5407, 0.6737, 0.5260, 0.8009, 0.6307, 0.6026,0.5197, 0.7532, 0.4754, 0.6674, 0.6768, 0.7643, 0.6705, 0.7871, 0.6135, 0.7762, 0.6081, 0.4060, 0.3688, 0.5848, 0.4235, 0.6011, 0.6949, 0.4410,0.8054, 0.7706, 0.3644, 0.6820, 0.6351, 0.4282, 0.4613, 0.7392, 0.5208,0.4409, 0.5589, 0.3401, 0.5811, 0.7109, 0.3245, 0.5017, 0.6650, 0.5949,0.5680, 0.4445, 0.7482, 0.3044, 0.7760, 0.4396, 0.4067, 0.3840, 0.7426,0.5989, 0.5169, 0.7056, 0.4329, 0.5555]

What i want to do is each time the index value of the array reach 9 , it will print a new line before it continues printing the next array value. So what i expect it will print the array like this :

[0.8067, 0.7152, 0.4551, 0.7519, 0.3419, 0.7161, 0.3793, 0.6859, 0.4205,
    0.5129, 0.5534, 0.5995, 0.4999, 0.5136, 0.8194, 0.4855, 0.6822, 0.4924,
    0.5359, 0.4083, 0.5078, 0.7260, 0.6876, 0.7033, 0.5777, 0.4515, 0.5460,
    0.5842, 0.7296, 0.7570, 0.4579, 0.3252, 0.4683, 0.3646, 0.3220, 0.4150,
    0.3263, 0.6402, 0.3184, 0.7087, 0.2958, 0.5384, 0.5462, 0.3933, 0.2963,
    0.6883, 0.4766, 0.5430, 0.4943, 0.2810, 0.4785, 0.5618, 0.6941, 0.4943,
    0.3793, 0.7629, 0.6058, 0.6419, 0.4902, 0.3158, 0.7923, 0.7335, 0.5624,
    0.5390, 0.5337, 0.8333, 0.7519, 0.6591, 0.5301, 0.3020, 0.8187, 0.8084,
    0.3412, 0.7912, 0.6240, 0.4296, 0.4908, 0.6560, 0.7366, 0.5219, 0.8128,
    0.3683, 0.6037, 0.4570, 0.3640, 0.4717, 0.5948, 0.6294, 0.8222, 0.7323,
    0.4344, 0.4371, 0.5013, 0.2913, 0.4335, 0.4046, 0.6788, 0.5917, 0.8369,
    0.8983, 0.3981, 0.8857, 0.4309, 0.6197, 0.7020, 0.3666, 0.5837, 0.3259,
    0.7193, 0.3719, 0.7098, 0.4088, 0.5421, 0.5039, 0.3664, 0.5499, 0.8648,
    0.3217, 0.7696, 0.5970, 0.4611, 0.3465, 0.6396, 0.6688, 0.5773, 0.7444,
    0.7232, 0.5695, 0.5801, 0.5218, 0.8099, 0.6983, 0.5733, 0.3286, 0.6736,
    0.6470, 0.9196, 0.7589, 0.7610, 0.8454, 0.6261, 0.6229, 0.7600, 0.5022,
    0.3035, 0.5229, 0.5353, 0.4962, 0.8466, 0.1817, 0.5271, 0.6928, 0.7898,
    0.4182, 0.5234, 0.4112, 0.4812, 0.7522, 0.4209, 0.7217, 0.6545, 0.6954,
    0.3139, 0.5253, 0.5467, 0.3606, 0.6640, 0.7399, 0.7965, 0.5742, 0.5729,
    0.6213, 0.7981, 0.5613, 0.4904, 0.7292, 0.5686, 0.8421, 0.7316, 0.6408,
    0.6550, 0.3902, 0.5353, 0.5459, 0.4035, 0.3390, 0.4407, 0.7370, 0.4466,
    0.4029, 0.8216, 0.4862, 0.7136 ]

How can i achieve this? Thank you in advance.

Try this

for i in range(len(arr)):
    if i%9 == 0:
        print()
    print(arr[i], end = " ")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM