I'm a beginner at Python. I couldn't find what I wanted even if I searched it. I ask for your help me.
List1 = [{'id':1}, {'id':2}, {'id':3 }, {'id':4}]
List2 = [{'id':1}, {'id':4}]
If you compare the value of list1 with the value of list2 in order and get the same value, You want to organize a specific function to run.
python list compare
The dictionaries in each list have the same key. This means that you only need to use the value.
>>> List1 = [{'id':1}, {'id':2}, {'id':3 }, {'id':4}]
>>> List2 = [{'id':1}, {'id':4}]
>>> intersection_items = set([item['id'] for item in List1]) & set([item['id'] for item in List2]) # Find the intersection (equal value) in the dictionary of the two lists.
>>> list(map(lambdai:i*2, intersection_items)) # Apply a function that multiplies the items of the intersection by 2.
© 2024 OneMinuteCode. All rights reserved.