2015-03-18 46 views
0

,所以我是新來的蟒蛇,我想其中有一個大寫字母開頭的文本過濾掉所有的話讓我有限的知識到Python我這樣做:去除的話開頭大寫

def filterupper(text): 
    upper = string.ascii_uppercase 
    filteredupper = [w for w in text not in startswith(upper)] 
return filteredupper 

這個錯誤就

File "<pyshell#58>", line 3, in filterupper 
filteredupper = [w for w in text not in startswith(upper)] 

NameError:全局名稱 'startswith' 沒有定義

所以我想這:

def filterupper(text): 
    upper = string.ascii_uppercase 
    filteredupper = [w for w in text not in upper] 
return filteredupper 

這個錯誤傳來:

File "<pyshell#55>", line 3, in filterupper 
filteredupper = [w for w in text not in upper] 
TypeError: 'in <string>' requires string as left operand, not list 

所以任何一個可以告訴我如何刪除單詞以大寫開頭,並告訴我,我在這些代碼做錯了

謝謝

回答

0

請嘗試使用str.islower()檢查字母是否小寫:

def filterupper(text): 
    return " ".join([word for word in text.split() if word[0].islower()]) 

>>> filterupper("My name is Bob And I am Cool") 
"name is am" 
>>>