Skip to main content
 首页 » 编程设计

Python len() 不好

2025年05月04日11开发

<分区>

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

但是当我得到长度时:

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 
+--+ 
--+++- 
-+--+-- 
++--- 
-++-- 
--+-+++----------------+-+ 
+-++--+ 
-+-+++-+ 
-+--+-+ 
--+++- 
-+--+- 
++-- 
-+-- 
-++----------------+-+ 
+-++-+--+ 
-+-+++- 
-+--+-+- 
++---+ 
-++-+- 
--+-+++---+-------------+-+ 
+-++--+