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

时间:2011-09-12 03:21:33

标签: python

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

尝试:

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 个答案:

答案 0 :(得分:2)

.split()是一个用于字符串的方法,用于将其分解为数组。你的单词已经在一个数组中,不需要拆分。

阅读您收到的错误消息;它通常会让你知道发生了什么。