Answer the question
In order to leave comments, you need to log in
Which procedure is best?
There is a list of dictionaries in python 2.7
#несколько тысяч объектов с десятком параметров
data = [{'a': 1, 'b': 2},{'a': 2, 'b': 2},{'a': 1, 'b': 100},{'a': 1, 'b': 22},{'a': 3, 'b': 2}]
#Искомые параметры
filtr = {'a': 1}
#Вариант 1
data = [ x for x in data if set(filtr.items()).issubset(set(x.items())) ]
#Вариант 2
data = [ x for x in data if set(x.items()).issuperset(set(filtr.items())) ]
#Вариант 3
data = list(filter(lambda x:set(filtr.items()).issubset(set(x.items())),data))
new_data = []
while len(data)>0:
item = data.pop()
if set(filtr.items()).issubset(set(item.items())):
new_data.insert(0,item)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question