如果我有一个日期数组:
["2012-1-1", "2012-1-3","2012-5-3"]我希望能够获得以下结果列表:
["January 2012", "May 2012"]做这件事最好的方法是什么?
发布于 2013-02-22 02:03:43
[datetime.datetime.strptime(d, '%Y-%m-%d').strftime("%B %Y") for d in my_list]发布于 2013-02-22 03:08:15
如果你想按日期时间和剔除唯一性进行排序,我会分三部分来做:
dates = [datetime.datetime.strptime(d, '%Y-%m-%d') for d in my_list]
dates.sort()
string_dates = [d.strftime("%B %Y") for d in dates]
## now we'll cull the list of duplicates
import itertools
[ grouped[0] for grouped in itertools.groupby(string_dates) ]https://stackoverflow.com/questions/15009145
复制相似问题