调试:在单词列表中找到中间单词

-4 投票
1 回答
1332 浏览
提问于 2025-04-17 02:04

目的:在一个单词列表中找到中间的单词

尝试:

words = ['Baa', 'Baa', 'black', 'sheep', 'have', 'you', 'any', 'wool']
s=words.split('')
length = len(words)
 if length % 2 == 1:
  print s(length/2)
 else:
  print s((length/2) + ((length/2) +1))

Error: Traceback (most recent call last):  
  File "<web session>", line 2, in <module> 
AttributeError: 'list' object has no attribute 'split' 

1 个回答

2

.split() 是一个用于字符串的方法,它可以把字符串分割成一个数组。你的单词已经在一个数组里了,所以不需要再分割。

看看你收到的错误信息;通常它会给你一些提示,告诉你发生了什么问题。

撰写回答