如果我有week = [{'Weekdays': 5, 'Weekends': 2}]
之类的列表,是否可以从week = {'Weekdays': 5, 'Weekends': 2}
的数据类型为week
的同一位置获取dict
?< / p>
答案 0 :(得分:0)
索引列表week = week[0]
并指定
In [26]: week = [{'Weekdays': 5, 'Weekends': 2}]
In [27]: week = week[0]
In [28]: week
Out[28]: {'Weekdays': 5, 'Weekends': 2}
答案 1 :(得分:0)
确保有一周,然后抓住它。你知道总会有一个星期吗?
if week: week = week[0]