我有一个movietimes={}
这是我的一句格言:
for i in Showtime.objects.filter(movie_id=movieid,theater_id=theaterid,datetime__range=(today,tomorrow))):
if i.mvtype not in movietimes:
movietimes[i.mvtype] = []
if not i.movietime > today :
movietimes[i.mvtype].append(i.movietime.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
if not movietimes : #this have bug
for i in Showtime.objects.filter(movie_id=movieid,datetime__range=(yesterday,today)):
if i.mvtype not in movietimes:
movietimes[i.mvtype] = []
movietimes[i.mvtype].append(i.movietime.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
return movietimes
结果如下:
"Times": {
"ONE: [
"2014-12-24T10:40:00.000000Z",
"2014-12-24T12:45:00.000000Z",
"2014-12-25T14:50:00.000000Z"
]
}
我想问,如果“ONE”部分中的[]
是空的,我怎么能判断呢??你知道吗
我不能使用if not movietimes={}:
,因为dict中有u'ONE': []
我得判断字典里的第一个单子是空的。有很多种类型,一,二,三
它们被i.mvtype
捕获
{u'ONE': []}
{u'TWO': []}
{u'Three': []}
请帮帮我,谢谢
这是假定首先你的意思是键
ONE
,因为dict没有排序如果您想查看是否有空列表,您的dict如下所示:
相关问题 更多 >
编程相关推荐