开发者

Debug: find the middle word(s) in a list of words [closed]

开发者 https://www.devze.com 2023-04-04 17:04 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the h开发者_运维知识库elp center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消