提取dict中的值

时间:2018-08-30 23:17:24

标签: python python-3.x dictionary

我有这个字典:

data = {'name':['Andrea', 'Luca'], 'age':['14', '15']}

我写:

for key, value in data.items():
    print (key, value)

在这里,我在(print(key,value))中的结果是:

name ['Andrea', 'Luca']
age ['14', '15']

我想提取这个:

name = Andrea
name = Luca
age = 14
age = 15

我该怎么办?

2 个答案:

答案 0 :(得分:3)

只需添加一个内部template<class... Args> auto uninitialized_construct(Args&&... args){ typename array::element_ptr cur = this->data(); for(size_type n = this->num_elements(); n > 0; --n, ++cur) alloc_traits::construct(allocator_, std::addressof(*cur), args...); }catch(...){destroy(cur); throw;} } 循环:

template<class... Args>
auto uninitialized_construct(Args&&... args){
    std::unitialized_fill_n(data_, n, T(args...)); // or should I construct a copy first?
}

答案 1 :(得分:1)

value是您的列表。遍历并打印每个项目。

for key, value in data.items():
    for x in value:
        print('{} = {}'.format(key, x))