gpt4 book ai didi

Python len() 不好

转载 作者:太空宇宙 更新时间:2023-11-04 07:16:30 28 4
gpt4 key购买 nike

<分区>

我有一个文件,我想获取行的长度。

但是当我得到长度时:

8 10 11 9 9 30 11 12 11 10 10 8 8 26 13 etc...

这是我的代码:

competition = []
with open('verseny.txt') as f:
competitor_number= int(next(f))
for line in f:
shots = line.split()
competition.append(str(shots))

for num,shots in enumerate(competition, 1):
if '++' in shots:
print(num, end=",")

print("\n")

for shots in competition:
print(len(shots))

verseny.txt 的内容是:

21
+--+
--+++-
-+--+--
++---
-++--
--+-+++----------------+-+
+-++--+
-+-+++-+
-+--+-+
--+++-
-+--+-
++--
-+--
-++----------------+-+
+-++-+--+
-+-+++-
-+--+-+-
++---+
-++-+-
--+-+++---+-------------+-+
+-++--+

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com