Purpose: find the middle word(s) in a list of words
Attempt:
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'
.split()
is a method used for a string, to break it into an array. Your words are already in an array and do not need to be split.
Read the error message you are receiving; it will usually give you a clue what's going on.
精彩评论