有没有办法用列表列表来压缩列表?例如,您有两个列表:
lst1 = ['food', 'drinks', 'sports']
lst2 = [['hamburger', 'beer', 'football'], ['cheeseburger', 'wine', 'tennis']]
然后您将得到:
[{'food':'hamburger', 'drinks':'beer', 'sports':'football'},
{'food':'cheeseburger', 'drinks':'wine', 'sports':'tennis'}]
有没有办法做到这一点?
答案 0 :(得分:3)
合并字典的结构和列表理解:
$res->sq = mysqli_fetch_object($sql)->sq;
$res->poam = mysqli_fetch_object($sql)->poam;