擅长:python、mysql、java
<p>正如你所说,名字是以大写字母开头的。所以我写了这段代码,希望对大家有所帮助:</p>
<pre><code>string = 'Bob plays, draws Jane, Nicky lives in a house'
splitedString = string.split(",")
finalDict = {}
for sentence in splitedString:
splitedSentence = sentence.split()
name = ''
toDo = ''
for word in splitedSentence:
if(word[0].isupper()):
name = word
else:
toDo = toDo + " " + word
finalDict[name.strip()] = toDo.strip()
print(finalDict)
</code></pre>
<p><strong>输出</strong></p>
<pre><code>{'Bob': 'plays', 'Jane': 'draws', 'Nicky': 'lives in a house'}
</code></pre>