There are two vocabulary lists:

The first:

x = {'title':'[Лада]', 'prise':'[70000]', 'status':'[Непродана]'},{'title':'[нисан]', 'prise':'[70000]', 'status':'[Непродана]'} 

Second:

 y = {'title':'[Лада]', 'prise':'[70000]', 'status':'[Продана]'},{'title':'[БМВ]', 'prise':'[70000]', 'status':'[Непродана]'} 

Desired result:

  z = {'title':'[Лада]', 'prise':'[70000]', 'status':'[Продана]'},{'title':'[нисан]', 'prise':'[70000]', 'status':'[Непродана]'}, {'title':'[БМВ]', 'prise':'[70000]', 'status':'[Непродана]'} 

    3 answers 3

    Pandas does a great job with these tasks:

     import pandas as pd def merge(*args): return (pd.concat([pd.DataFrame(x if isinstance(x, list) else list(x)) for x in args], ignore_index=True) .drop_duplicates('title', keep='last')) def merge2(*args): return (pd.concat([pd.DataFrame(x if isinstance(x, list) else list(x)) for x in args], ignore_index=True) .drop_duplicates('title', keep='last') .to_dict('records')) 

    In the form of Pandas DataFrame:

     In [72]: merge(x, y) Out[72]: prise status title 1 [70000] [Непродана] [нисан] 2 [70000] [Продана] [Лада] 3 [70000] [Непродана] [БМВ] 

    In the form of a list of dictionaries:

     In [73]: merge2(x, y) Out[73]: [{'prise': '[70000]', 'status': '[Непродана]', 'title': '[нисан]'}, {'prise': '[70000]', 'status': '[Продана]', 'title': '[Лада]'}, {'prise': '[70000]', 'status': '[Непродана]', 'title': '[БМВ]'}] 
    • Uraaa, was it possible someone could help, fought for 3 days, googled everything and everyone Thank you very much! - Sergey Smishko
    • Is it possible to contact you in personal messages? - Sergey Smishko
    • @ Sergey Smishko, I try hard not to advertise my data online ... And what did you want? - MaxU
    • Everything is about the same and the same, everything works on these lines, but if I take two csv files to compare the same method, I get an error - Sergey Smishko
    • Ask a new question and provide data that will help reproduce the problem ... - MaxU
     z = {} for d in sorted((d for o in (x, y) for d in o), key=lambda d: d['status'] == '[Непродана]'): t = d['title'] if t not in z: z[t] = d z = list(z.values()) print('\n'.join(map(str, z))) # {'title': '[Лада]', 'prise': '[70000]', 'status': '[Продана]'} # {'title': '[нисан]', 'prise': '[70000]', 'status': '[Непродана]'} # {'title': '[БМВ]', 'prise': '[70000]', 'status': '[Непродана]'} 

      Note the first is not a dictionary but a list containing dictionaries.

      Combine dictionaries:

       x = {'title':'[Лада]', 'prise':'[70000]', 'status':'[Непродана]'},{'title':'[нисан]', 'prise':'[70000]', 'status':'[Непродана]'} y = {'title':'[Лада]', 'prise':'[70000]', 'status':'[Продана]'},{'title':'[БМВ]', 'prise':'[70000]', 'status':'[Непродана]'} x.update(y) print "Value : %s" % x 
      • This is a non-working code. - Enikeyschik