字典将存储电影的名称,对于每部电影,字典值将是显示时间列表。
我无法理解。这是正确的吗?
movie A: 9,11,15 movie B: 10,14,6 movie C: 11,13,19
dictionary={"moviesA":0, "moviesB":0, "moviesC":0}
showingtimes={"moviesA": 9, "moviesA": 11, "moviesA": 15, "moviesA": 21, "moviesB" : 10, "moviesB": 14, "moviesB": 16,
"moviesC": 11, "moviesC":13, "moviesC":19, "moviesC": 20, "moviesC": 21, "movieC":22}
答案 0 :(得分:0)
使用list
存储您的放映时间。您的词典的key
将是电影的名称,其value
是放映时间列表。
d["movieA"] = [9, 11, 13, 15]
d["movieB"] = [13, 17]
答案 1 :(得分:0)
将其存储起来:
data1={'movie A': [9,11,15], 'movie B': [10,14,6], 'movie C': [11,13,19]}
现在,如果你想按时间检查,你可以这样做:
#which movies shows available at 11 ?
def check_by_time(time_mo):
movies_list=[]
for i, j in data1.items():
if time_mo in j:
movies_list.append(i)
return movies_list
print(check_by_time(11))
输出:
['movie A', 'movie C']