Python 3.5 iterate through a list of dictionaries

前端 未结 4 1289
深忆病人
深忆病人 2020-12-23 10:34

My code is

index = 0
for key in dataList[index]:
    print(dataList[index][key])

Seems to work fine for printing the values of dictionary k

4条回答
  •  时光取名叫无心
    2020-12-23 10:50

    def extract_fullnames_as_string(list_of_dictionaries):
        
    return list(map(lambda e : "{} {}".format(e['first'],e['last']),list_of_dictionaries))
    
    
    names = [{'first': 'Zhibekchach', 'last': 'Myrzaeva'}, {'first': 'Gulbara', 'last': 'Zholdoshova'}]
    print(extract_fullnames_as_string(names))
    
    #Well...the shortest way (1 line only) in Python to extract data from the list of dictionaries is using lambda form and map together. 
    
    

提交回复
热议问题