0

prints elements from a list with 10 digits per line from this

n = [85, 13, 99, 34, 71, 15, 82, 24, 64, 61,
     67, 99, 50, 68, 25, 37, 32, 27, 14, 91,
     79, 15, 47, 48, 74, 88, 64, 53, 77, 50,
     24, 91, 87, 55, 60, 75, 91, 22, 47, 63,
     81, 88, 26, 48, 69, 59, 84, 77, 28, 36,
     59, 74, 89, 73, 91, 64, 55, 88, 90, 48,
     73, 97, 98, 40, 93, 50, 78, 60, 44, 77,
     82, 51, 53, 65, 98, 59, 94, 91, 52, 44,
     65, 85, 72, 92, 49, 67, 58, 48, 62, 54,
     89, 67, 58, 48, 85, 45, 77, 76, 81, 77]

to this (without parenthesis)

value n :
85, 13, 99, 34, 71, 15, 82, 24, 64, 61, 
67, 99, 50, 68, 25, 37, 32, 27, 14, 91, 
79, 15, 47, 48, 74, 88, 64, 53, 77, 50, 
24, 91, 87, 55, 60, 75, 91, 22, 47, 63, 
81, 88, 26, 48, 69, 59, 84, 77, 28, 36, 
59, 74, 89, 73, 91, 64, 55, 88, 90, 48, 
73, 97, 98, 40, 93, 50, 78, 60, 44, 77, 
82, 51, 53, 65, 98, 59, 94, 91, 52, 44, 
65, 85, 72, 92, 49, 67, 58, 48, 62, 54, 
89, 67, 58, 48, 85, 45, 77, 76, 81, 77
HezTech
  • 29
  • 3

4 Answers4

0

You can just you simply to get desired output using separator in print

print('value n :')
for i in range(0, len(n), 10):
    print(*n[i:i+10], sep = ', ')

Explanation

  1. range(0, len(n), 10) creates starting index on each row
  2. n[i:i+1] is the array of 10 values for each row
  3. *n[i:i+1] is the unpacking operator that turns list n[i:i+1 into positional arguments for print (i.e. equivalent to print(n[i], n[i+1], ...n[i+10])
  4. sep = ', ' causes each positional argument to be printed with a comma separator
DarrylG
  • 16,732
  • 2
  • 17
  • 23
0

You can try this:

n = [85, 13, 99, 34, 71, 15, 82, 24, 64, 61,
     67, 99, 50, 68, 25, 37, 32, 27, 14, 91,
     79, 15, 47, 48, 74, 88, 64, 53, 77, 50,
     24, 91, 87, 55, 60, 75, 91, 22, 47, 63,
     81, 88, 26, 48, 69, 59, 84, 77, 28, 36,
     59, 74, 89, 73, 91, 64, 55, 88, 90, 48,
     73, 97, 98, 40, 93, 50, 78, 60, 44, 77,
     82, 51, 53, 65, 98, 59, 94, 91, 52, 44,
     65, 85, 72, 92, 49, 67, 58, 48, 62, 54,
     89, 67, 58, 48, 85, 45, 77, 76, 81, 77]

print("value n :")

for x in range(10):
    print(', '.join([str(num) for num in (n[x*10:x*10+10])]))

Output:

value n : 
85, 13, 99, 34, 71, 15, 82, 24, 64, 61
67, 99, 50, 68, 25, 37, 32, 27, 14, 91
79, 15, 47, 48, 74, 88, 64, 53, 77, 50
24, 91, 87, 55, 60, 75, 91, 22, 47, 63
81, 88, 26, 48, 69, 59, 84, 77, 28, 36
59, 74, 89, 73, 91, 64, 55, 88, 90, 48
73, 97, 98, 40, 93, 50, 78, 60, 44, 77
82, 51, 53, 65, 98, 59, 94, 91, 52, 44
65, 85, 72, 92, 49, 67, 58, 48, 62, 54
89, 67, 58, 48, 85, 45, 77, 76, 81, 77
Sushil
  • 5,440
  • 1
  • 8
  • 26
0
y = [", ".join([str(x) for x in n[10*(i-1):10*i]]) for i in range(1, 11)]
print("\n".join(y))

I first splitter the original list into 10 sublists, turned each one to a string, and then concat those strings.

Tom Ron
  • 5,906
  • 3
  • 22
  • 38
0

Input:

n = [85, 13, 99, 34, 71, 15, 82, 24, 64, 61,
     67, 99, 50, 68, 25, 37, 32, 27, 14, 91,
     79, 15, 47, 48, 74, 88, 64, 53, 77, 50,
     24, 91, 87, 55, 60, 75, 91, 22, 47, 63,
     81, 88, 26, 48, 69, 59, 84, 77, 28, 36,
     59, 74, 89, 73, 91, 64, 55, 88, 90, 48,
     73, 97, 98, 40, 93, 50, 78, 60, 44, 77,
     82, 51, 53, 65, 98, 59, 94, 91, 52, 44,
     65, 85, 72, 92, 49, 67, 58, 48, 62, 54,
     89, 67, 58, 48, 85, 45, 77, 76, 81, 77]

Code:

    print('value n:')
    for i in range(0, n.__len__(), 10):
        print(*n[i:i+10], sep=', ',end='\n')

Output:

value n:
85, 13, 99, 34, 71, 15, 82, 24, 64, 61
67, 99, 50, 68, 25, 37, 32, 27, 14, 91
79, 15, 47, 48, 74, 88, 64, 53, 77, 50
24, 91, 87, 55, 60, 75, 91, 22, 47, 63
81, 88, 26, 48, 69, 59, 84, 77, 28, 36
59, 74, 89, 73, 91, 64, 55, 88, 90, 48
73, 97, 98, 40, 93, 50, 78, 60, 44, 77
82, 51, 53, 65, 98, 59, 94, 91, 52, 44
65, 85, 72, 92, 49, 67, 58, 48, 62, 54
89, 67, 58, 48, 85, 45, 77, 76, 81, 77

Output

Jaied
  • 900
  • 9
  • 13