當前位置:成語大全網 - 新華字典 - 在python中怎麽把列表中的元素添加到字典中

在python中怎麽把列表中的元素添加到字典中

>>>?a=['one','two','three']

>>>?b={}

>>>?[b.setdefault(x,y)?for?x,y?in?enumerate(a)]

['one',?'two',?'three']

>>>?b

{0:?'one',?1:?'two',?2:?'three'}

>>>