擅长:python、mysql、java
<p>字典不能有重复的键。例如,它只能有一个键<code>'Jacob Rasnip'</code>。你的例子显示了两个。
类似地,字典只能有一个键<code>'Apr'</code>。你知道吗</p>
<p>如果您将用户名的dictorial映射到<code>datetime.date</code>的<strong>列表</strong>:</p>
<pre><code>{'Jacob Rasnip': [datetime.date(2011,4,1),datetime.date(2011,5,1),]...}
</code></pre>
<p>然后你就可以用</p>
<pre><code>for user,dates in user_dict.iteritems():
first_date = min(dates)
last_date = max(dates)
print(user,first_date,last_date)
</code></pre>
<p>注意<code>min</code>和<code>max</code>依赖于<code>dates</code>中的项是<a href="http://docs.python.org/library/datetime.html#module-datetime" rel="nofollow">datetime.date</a>对象。它还可以处理表示月份的简单整数(假设所有月份都指同一年)。但是对于月份的字符串名称,它不能像预期的那样工作(例如<code>'Apr'</code>)。你知道吗</p>