文本划分

发布于 2025-01-25 11:28:20 字数 1217 浏览 1 评论 0原文

您好,谢谢您的任何帮助,我需要帮助

我有此代码 他读了5-10行,但我需要重新进行它,

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

我正在寻找此输出的

第一个输入第二是输出图像

“在此处输入映像”

输入

    1-100 lines

IM搜索此数字搜索列表中的search in List

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

print(xx(num))

Output utpute行只有文本

[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]

只需

从1到10向下从11到20下向下等...

线上有文本,因此,例如,所有10个文本都合并为一个,

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

这只是一个示例,我的文本为33,000行

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2025-02-01 11:28:20

将10添加到列表索引,以便以后获取第10行的内容。

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文