我有一个词典列表,我需要使用其他词典列表中的信息进行更新。我当前的解决方案(如下)的工作方式是从第一个列表中取出每个词典,然后将其与第二个列表中的每个词典进行比较。它可以工作,但是有没有更快,更优雅的方法来达到相同的结果?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="clothing">
<img id="Haorijacketimg" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxISERUQEhIVFhUXFRYSGBYYFRcWGRUYGxgXGBcbGBgYHSggGBolHRUVITEiJSkrLi4uFx8zODMtNygtLisBCgoKDg0OFhAPFS0dFRkrKy0tKysrKystNy0tKy0rLS03Ky0rLSs3LSs4LSstKzc3NysrNysrLSs3LSstKysrK//AABEIAQ0AuwMBIgACEQEDEQH/xAAcAAEAAgMBAQEAAAAAAAAAAAAABQYDBAcBAgj/xABDEAABAwIDBQQHBQYEBwEAAAABAAIRAyEEEjEFBkFRYRMicYEHMkJSkaHBFGKx0fAjJHKCkrKiwuHxMzRDU2STsxX/xAAXAQEBAQEAAAAAAAAAAAAAAAAAAQID/8QAHBEBAQEAAQUAAAAAAAAAAAAAAAERAiExMkFC/9oADAMBAAIRAxEAPwDuKIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgKIqb0YFrgw4zDBxkQa9Oba2zdCq36Td7Bhqf2ak79rUHeIN6bD+DnXA5CTyX5tfiC2s+eBcB4F0q4P1/hds4aq7JTxFF7oJysqscYGpgGYW8vyPsbaj6dRmIpPy1KYJaRzkfEcwdZX6T3D3rZtHDCqAG1WwyrT913Aj7jtQfEagpYLKiIoCIiAiIgIiICIiAiIgIiICIiAsVeu1glzgB1WjtDaoZ3WwXfIfmq5jaxcZeSSpqJfGbxtFqbZ6mw+Gv4KHr7XxDgSahFrBsCOsgStUvCxVatoUH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zDU5GjnDtHDwc+SFMoiD1F4iD1ERAREQEREBERAReIg9ReIg9ReL1AREQEREBF4vUBEXiD1ERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQf/Z"width="50" height="50"/>
<br/>
<span class="quickview__icon" id="Haori jacket">
Quick View
</span>
<br/>
<span>
Haori jacket
</span>
<br/>
<span id="Haorijacketprice">
$210.00
</span>
<span id="Haorijacketnum" style="display: none;">1</span>
</div>
<br/>
<div class="clothing">
<img id="Linentopimg" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSHnKUQNqUcYm7fauoZSam3_c4gne4NemeUUyY2-RkvGWuOGR6O6g" width="50" height="50"/>
<br/>
<span class="quickview__icon" id="Linen top">Quick View</span>
<br/>
<span>Linen top</span>
<br/>
<span id="Linentopprice">
$170.00
</span>
<span id="Linentopnum" style="display: none;">2</span>
</div>
<div class="clothing">
<img id="T-shirtimg" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBw8PDw8PDw0NDw8QDw0PDQ0NDQ8NDQ8NFREWFhURFRUYHSggGBolGxUVITEhJSkrLzouFx8/ODUtNygtLisBCgoKBQUFDgUFDisZExkrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrK//AABEIAOEA4QMBIgACEQEDEQH/xAAbAAEAAwEBAQEAAAAAAAAAAAAAAQIEAwUGB//EAEUQAAIBAwAECQYJCwUAAAAAAAABAgMEEQUGITESMkFRYXFygbETImKRocEHIyQzQlJzgrIXQ0RkkqKjs8LR4RQ0U2Px/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AP3EAAAAAAAAAAAAABzq1ox37+ZbzNVrSkvq7tz2vvA2gwQrVFu29+TorqXLTfcBrIM3+s9CXqId4+SD7wNQMUq9R8ij3ladSafGyuVNtruYG8HKncJ7Hs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JdFEWQF0WRUlAWBCJAAEAQyrLFWBDKSLMq0B5msi+SXH2Fb2Rz7j3NCvNvS7EfA8fTqza3C56Ndfw5HqavSza0X6EfAD0QAAAAAAAAAAAAAAAAAAPOun8ZLoSPRPLun8ZPu/CgKRLnNHRICUy6KIugJBBIAEZGQBDJyVAqyCWVYGLS22hVX/XU/CzbqrLNnQfoR8DJffNzzucZeB11MlmxodheAHuAAAAAAAAAAAAAAAAAAAfP6fvZW8uG7erVg8ZdHgynF9ltZ9Z9ARKKe9J9YHxVPXOzXHV1T7drUeP2Mmyjrbo6X6ZSj9rGpR/HFH0U7GlLfSg/uoyVtAWk99Cn+ygMdHTljPi3tnLoVzSz6smuN1RlxatJ9VSL95jq6m2Mt9CPqRkqfB9o9/mV6gPejh7sPqeSeB0M+Yl8G2j3up46iv5ObRcWdSPVJoD6ng9BHB6D5j8n1Jbrm5XVWqL3kP4P4PfeXTXM69R+8D6eUUtr2Lp2GSvpG2p/OXNvD7SvTh4s8FfBpZvbNym+eT4T9profB/o+H5pMC9bWvRsd99bP7OflfwZMNXXnR/0alep9na1/6oo9uhqpZQ3UId6RupaIt48WjTX3UB8Nfa2yrRdOzsbmU5JxjUrxjTpxzs4WE23jm2H2WrFnKhaUacuNGKTXcehTt4R4sIrqSOoAAAAAAAAAAAQCQAAAAAACAAAAAAAAAAJAAAAAAAAAAAAAAAAAAEAAD/2Q==" width="50" height="50"/>
<br/>
<span class="quickview__icon" id="T-shirt">Quick View</span>
<br/>
<span>T-shirt</span>
<br/>
<span id="T-shirtprice">
$50.00
</span>
<span id="T-shirtnum" style="display: none;">3</span>
</div>
<div class="popup" style="display: none;" id="popup">
<span class="close" id="closepopup" title="Close">×</span>
<br/>
<img src="" id="popupimg" width="100" height= "100"/>
<br/>
<div style="width: 100%; position: relative">
<img id="previous" src="https://image.flaticon.com/icons/svg/60/60965.svg" height="50" width="50" style="position: absolute; left: 3px;"/>
<img id="next" src="https://image.flaticon.com/icons/svg/60/60758.svg" height="50" width="50" style="position: absolute; right: 3px;"/>
</div>
<div style="width: 100%; text-align: center;">
<span id="clothingname"></span>
<br/>
<span id="clothingprice"></span>
</div>
<br/>
</div>
答案 0 :(得分:3)
使用第一个数组创建由id
索引的字典。
使用id
遍历第二个数组。
for replacement in b:
v = lookup.get(replacement['id'], None)
if v is not None:
v['score'] = replacement['newscore']
这会将O(n^2)
问题转换为O(n)
问题。
答案 1 :(得分:1)
将b转换为更易于使用的方法,而不是进行len(a)* len(b)循环:
In [48]: replace = {d["id"]: {"score": d["newscore"]} for d in b}
In [49]: new_a = [{**d, **replace.get(d['id'], {})} for d in a]
In [50]: new_a
Out[50]: [{'id': 1, 'score': 500}, {'id': 2, 'score': 600}, {'id': 3, 'score': 400}]
请注意,{**somedict}
语法要求使用现代版本的Python(> = 3.5。)
答案 2 :(得分:1)
列表理解:
[i.update({"score": x["newscore"]}) for x in b for i in a if i['id']==x['id']]
print(a)
输出:
[{'id': 1, 'score': 500}, {'id': 2, 'score': 600}, {'id': 3, 'score': 400}]
时间:
%timeit [i.update({"score": x["newscore"]}) for x in b for i in a if i['id']==x['id']]
输出:
100000 loops, best of 3: 3.9 µs per loop
答案 3 :(得分:0)
如果您愿意使用pandas
,而a,b是熊猫数据帧,那么这里是一个单行纸
a.loc[a.id.isin(b.id), 'score'] = b.loc[b.id.isin(a.id), 'newscore']
将a,b转换为数据帧很简单,只需使用pd.DataFrame.from_records
如果可以将“ newscore”更改为“ score”,则可以使用另一种方法
a = pd.DataFrame.from_records(a, index="id")
b = pd.DataFrame.from_records(b, index="id")
a.update(b)
这是时间结果
In [10]: %timeit c = a.copy(); c.update(b)
702 µs ± 37.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
答案 4 :(得分:0)
首先创建分数更新字典:
>>> new_d={d['id']:d for d in b}
>>> new_d
{1: {'id': 1, 'newscore': 500}, 2: {'id': 2, 'newscore': 600}}
然后遍历a并通过id更新:
for d in a:
if d['id'] in new_d:
d['score']=new_d[d['id']]['newscore']
>>> a
[{'id': 1, 'score': 500}, {'id': 2, 'score': 600}, {'id': 3, 'score': 400}]
哪个可能更简单:
new_d={d['id']:d['newscore'] for d in b}
for d in a:
if d['id'] in new_d:
d['score']=new_d[d['id']]