Search code examples
pythonline

division of text in lines


hello and thank you for any help I need help

I have this code he reads the 5-10 lines but I need to remake it

f=open("input.txt", encoding='utf-8')
lines=f.readlines()
for x in range(5,10):
    print(lines[x])

I am looking for this output

first input second is output image

enter image description here

input

    1-100 lines

im search this number search in list

xx = lambda n:n and list(range(n,100,9))

print(xx(num))

output lines is text

[1, 11, 21, 31, 41, 51, 61, 71, 81, 91]
[2, 12, 22, 32, 42, 52, 62, 72, 82, 92]
[3, 13, 23, 33, 43, 53, 63, 73, 83, 93]
[4, 14, 24, 34, 44, 54, 64, 74, 84, 94]
[5, 15, 25, 35, 45, 55, 65, 75, 85, 95]
[6, 16, 26, 36, 46, 56, 66, 76, 86, 96]
[7, 17, 27, 37, 47, 57, 67, 77, 87, 97]
[8, 18, 28, 38, 48, 58, 68, 78, 88, 98]
[8, 18, 28, 38, 48, 58, 68, 78, 88, 98]
[9, 19, 29, 39, 49, 59, 69, 79, 89, 99]
[10, 20, 30, 40, 50, 60, 70, 80, 90,100]

just make a square

from 1 to 10 down from 11 to 20 down etc ...

there is text on the lines so that, for example, all 10 texts are combined into one

[1, 11, 21, 31, 41, 51, 61, 71, 81, 91]

this is just an example I have a long text of 33 thousand lines


Solution

  • Add 10 to the list index to get the contents of the line 10 rows later.

    with open("input.txt", encoding='utf-8') as f:
        lines = [line.rstrip() for line in f.readlines()]
    lines = [line.rstrip() for line in lines]
    for i in range(10):
        output_line = ",".join(lines[i+n] for n in range(0, 100, 10))
        print(output_line)