2013-12-09 2 views
3

함수를 정의해야합니다. vowelCount(). 입력은 단어 목록이고 나는 3 개의 키를 반환하는 사전을 반환해야합니다. 그것들은 모음보다 자음이 많은 단어를 포함하는 '자음'과 같은 모음을 가진 '모음이 많을수록'과 '양 모음'이 같은 '모음 모음'입니다. 그것은 DICT 더 속성 '추가'파이썬 def vowelCount() 사전을 생성합니다.

I가 없음을 sating 속성의 오류가 말을,

def voewlCount(wordList): 
    myDict = {} 
    vowelList = 'AEIOUaeiou' 
    contents = wordList.split() 
    for word in wordsList: 
     if vowelList in wordList == word: 
      myDict.append('half vowels') 
     elif vowelList in wordList > word: 
     myDict.append('more vowels') 
    else: 
     myDict.append('mostly consasants') 

내가 쉘을 실행할 때 오류 메시지가 점점 오전 : 여기

지금까지 내 코드입니다 나는 아직도 문제가 있어요 내 코드를 수정하지만 ... 여기 내 새로운 코드가 도움

def vowelContent(wordList): 
myDict = {'more consonants':[],'more vowels':[],'half vowels':[]} 
vowels = 'aeiouAEIOU' 
for word in wordList: 
    if vowels in wordList < word: 
     myDict['more consonants'].append(word) 
    elif vowels in wordLists > word: 
     myDict['more vowels'].append(word) 
    else: 
     myDict['half vowels'].append(word) 
return myDict 

say = ['do', 'you','know','the','definition','of','insanity','or','being','insane'] print(vowelContent(say))

주셔서 감사입니다 나는이 기능을 인쇄 할 때

은 목록에서 모든 단어 위 여기 시작하는 데 도움이되는 몇 가지 프레임 워크 년대 'more consonants'

+1

사전은 키/값 저장소와 같습니다. 사전에는 추가하지 않습니다. 사전에 항목을 추가하려면 다음과 같이 작성하십시오. myDict [ 'key'] = value – Rami

답변

2

에 배치됩니다. 당신은 내가 버린 논리를 채울 수 있습니다.

def helper(word): 
    """returns the number of vowels and consonants in the word, respectively""" 
    # you fill this in 
    return n_vowels, n_consonants 

def voewlCount(wordList): #sic 
    result = {'more consonants': [], 'more vowels': [], 'half vowels': []} 
    for word in wordList: 
    nv, nc = helper(word) 
    if #something: 
     result['more consonants'].append(word) 
    elif #something_else: 
     result['more vowels'].append(word) 
    elif #the other thing: 
     result['half vowels'].append(word) 
    else: 
     # well this can never happen (or can it)? 
    return result 
+0

단어에'vowels' 및'consonants '이외의 것이있을 수 있습니까 (예 : 문장 부호)? 도우미는 한 단어 안에있는 모음과 자음의 수를 비교하는'cmp'와 같은 함수 일 수 있습니다 (우리는 카운트가 필요없고 비교 만하는 것입니다) – jfs

관련 문제